简体   繁体   English

我该如何解决这个错误“参数类型'Object'不能分配给参数类型'int'

[英]how can i solve this error"The argument type 'Object' can´t be assigned to the parameter type 'int'

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我正在尝试获取字段列表中的“颜色”值,但它在“BoxDecoration(颜色:颜色(项目['颜色'])”行中显示了此错误int 或我在其他帖子中看到的字符串,但这不是我的情况

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"}
];

Convert to int转换为 int

Color(item['color'] as int)

Make sure the item color format is hex color确保项目颜色格式为十六进制颜色

replace the:更换:

item['color']

with

int.parse(item['color'])

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 参数类型“对象?” 不能分配给参数类型“int” - The argument type 'Object?' can't be assigned to the parameter type 'int' Flutter | 参数类型“对象?” 无法分配给参数类型“int” - Flutter | The argument type 'Object?' can't be assigned to the parameter type 'int' 错误:无法将参数类型“int”分配给参数类型“String” - Error: The argument type 'int' can't be assigned to the parameter type 'String' 参数类型 'List<string> ' 不能分配给参数类型 'String'。 我怎么解决这个问题?</string> - The argument type 'List<String>' can't be assigned to the parameter type 'String'. How can I solve this problem? 错误:参数类型“对象?” 不能分配给参数类型“字符串”? - ERROR: The argument type 'Object?' can't be assigned to the parameter type 'String?' 如何解决“参数类型&#39;ImageProvider<Object> &#39;不能分配给参数类型&#39;ImageProvider&#39;?”颤动 - How to solve "The argument type 'ImageProvider<Object>' can't be assigned to the parameter type 'ImageProvider'?" in flutter 错误参数类型“对象?” 不能分配给参数类型“颜色?” - Error The argument type 'Object?' can't be assigned to the parameter type 'Color?' 如何解决“无法将参数类型&#39;String&#39;分配给参数类型&#39;int&#39;” - Flutter - How can I resolve "The argument type 'String' can't be assigned to the parameter type 'int' " - Flutter 参数类型“String”不能分配给参数类型“int”我该如何解决? - The argument type 'String' can't be assigned to the parameter type 'int' how can i fix it? 为什么我会收到此错误:参数类型“String”不能分配给参数类型“int”? - Why I'm getting this error: The argument type 'String' can't be assigned to the parameter type 'int'?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM