Home > database >  how can i solve this error"The argument type 'Object' can´t be assigned to the parame
how can i solve this error"The argument type 'Object' can´t be assigned to the parame

Time:09-28

I am trying to get the value of "color" that I have in a list of fields but it shows me this error ni t he line "BoxDecoration( color: Color(item['color'])," Try to put as to int or as string as I saw in other posts but it is not my case

import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'proceso.dart';

class plan_educacional extends StatefulWidget {
 @override
State<plan_educacional> createState() => _plan_educacionalState();
}

class _plan_educacionalState extends State<plan_educacional> {
var itemList = data;
var listScrollController = new ScrollController();
var scrollDirection = ScrollDirection.idle;
 @override
 Widget build(BuildContext context) {
 return Scaffold(
     appBar: AppBar(title: const Text('Plan educacional')),
     body: Container(
      child: Center(
         child: Container(
            height: 300,
         padding: EdgeInsets.symmetric(vertical: 16),
         color: Color.fromARGB(255, 83, 145, 196),
          child: ListView(
             controller: listScrollController,
             scrollDirection: Axis.horizontal,
             children: data.map((item) {
             return Container(
                 color: Colors.white,
              width: 120,
              margin: EdgeInsets.symmetric(horizontal: 16, vertical: 16),
              decoration: BoxDecoration(
                  color: Color(item['color']), // this is the error line
                  borderRadius: BorderRadius.circular(16),
                  boxShadow: [
                    BoxShadow(
                        color: Color(item["color"]).withOpacity(0.6),
                        offset: Offset(-6, 4),
                        blurRadius: 10)
                  ]),
              );
           }).toList(),
                  ),
              ),
             ),
             ),
     );
     }
    }

this is where I have the values

this is where I have assigned the title, color and image that I want to appear on my card

    var data = [
{
    "title": "A New Occasion",
    "color": 0xff27ae60,
    "image": "assets/human1.png"
},
{"title": "Well Designed", "color": 0xff2980b9, "image": "assets/human2.png"},
{
    "title": "Includes Everyone",
    "color": 0xffc0392b,
 "image": "assets/human3.png"
},
{"title": "Great Spacing", "color": 0xff8e44ad, "image": "assets/human4.png"}
];

CodePudding user response:

Convert to int

Color(item['color'] as int)

Make sure the item color format is hex color

CodePudding user response:

replace the :

item['color']

with

int.parse(item['color'])
  • Related