简体   繁体   English

参数类型&#39;列表<dynamic> &#39; 不能分配给参数类型 &#39;List <Map<String, Object> &gt;&#39;

[英]The argument type 'List<dynamic>' can't be assigned to the parameter type 'List<Map<String, Object>>'

here is basically the entire code which is related to the error I suppose!!这里基本上是与我想的错误相关的整个代码! I am new to programming as well as Flutter, I tried to splitting the code into widgets so my code be cleaner.我是编程和 Flutter 的新手,我尝试将代码拆分为小部件,以便我的代码更干净。 that's where I got stuck by this message: The argument type 'List' can't be assigned to the parameter type 'List<Map<String, Object>>'.这就是我被这条消息卡住的地方:无法将参数类型“List”分配给参数类型“List<Map<String, Object>>”。 I hope it's clear now to be checked.我希望现在可以检查清楚。 thanks!谢谢!

my Main.dart code我的 Main.dart 代码

Quiz.dart code Quiz.dart 代码

import 'package:flutter/material.dart';
import 'package:quiz2/ui/question.dart';
import 'package:quiz2/ui/quiz.dart';
import 'package:quiz2/ui/result.dart';
import './ui/answer.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  MyApp({Key? key}) : super(key: key);

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  int _index = 0;
  final List _questions = const [
    {
      'questionText': 'who\'s your favorite football player? ',
      'Answers': ['Cristiano', ' Messi', 'Mbappe', 'Benzema']
    },
    {
      'questionText': 'who\'s your favorite Ping Pong player',
      'Answers': [
        'Noshad Alamian',
        'Nima Alamian',
        'Aria Amiri',
        'Matin Lotfollah Nassabi'
      ]
    },
    {
      'questionText': 'what\'s your favorite color',
      'Answers': ['Grey', 'Black', 'Green', 'Red']
    },
    {
      'questionText': 'what\'s your favorite football club',
      'Answers': ['Real Madrid', 'Barcelona', 'Manchester United', 'Liverpool']
    }
  ];
  void _answerQuestion() {
    if (_index < _questions.length) {
      debugPrint('we have more questions');
    } else {
      debugPrint('no more questions');
    }
    setState(() {
      _index = _index + 1;
    });
    debugPrint('answered !!');
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        appBar: AppBar(
          backgroundColor: Color.fromARGB(255, 115, 147, 163),
          title: Text('Quiz App'),
          centerTitle: true,
        ),
        backgroundColor: Colors.blueGrey.shade600,
        body: Container(
            child: _index < _questions.length
                ? Quiz(
                    index: _index,
                    answerQuestion: _answerQuestion,
                    questions: _questions)
                : Result()),
      ),
    );
  }
}

Problem might be with Flutter not properly defining type of your initialized list because you are creating type List (without any further specified generic type).问题可能在于 Flutter 没有正确定义初始化列表的类型,因为您正在创建类型 List(没有任何进一步指定的泛型类型)。

Change from从改变

 final List _questions = const [ ...

To

final _questions = const <Map<String,Object>>[ ...

Or或者

 final List<Map<String,Object>> _questions = const [ ...

Should do the trick应该做的伎俩

暂无
暂无

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

相关问题 Flutter 将 FromMap 转换为列表参数类型 'Object?' 不能分配给参数类型 'Map<string, dynamic> '</string,> - Flutter Convert FromMap to list The argument type 'Object?' can't be assigned to the parameter type 'Map<String, dynamic>' 参数类型 'Iterable <map<string, dynamic> >' 不能分配给参数类型 'List <map<string, dynamic> >' </map<string,></map<string,> - The argument type 'Iterable<Map<String, dynamic>>' can't be assigned to the parameter type 'List<Map<String, dynamic>>' 参数类型 'List <series<dynamic, dynamic> >' 不能分配给参数类型 'List <series<dynamic, string*> *>*' </series<dynamic,></series<dynamic,> - The argument type 'List<Series<dynamic, dynamic>>' can't be assigned to the parameter type 'List<Series<dynamic, String*>*>*' 错误:参数类型“列表<series<sales, string> >?' 不能分配给参数类型“列表<series<dynamic, string> >' </series<dynamic,></series<sales,> - Error: The argument type 'List<Series<Sales, String>>?' can't be assigned to the parameter type 'List<Series<dynamic, String>>' 参数类型“项目”不能分配给参数类型“列表”<dynamic> '</dynamic> - The argument type 'Item' can't be assigned to the parameter type 'List<dynamic>' 参数类型 'List<dynamic> ' 不能分配给参数类型 'Product'</dynamic> - The argument type 'List<dynamic>' can't be assigned to the parameter type 'Product' 参数类型&#39;列表<DropdownMenuItem<dynamic> &gt;&#39; 不能分配给参数类型 &#39;List <DropdownMenuItem<String> &gt;? - The argument type 'List<DropdownMenuItem<dynamic>>' can't be assigned to the parameter type 'List<DropdownMenuItem<String>>? 参数类型 &#39;List<string> &#39; 不能分配给参数类型 &#39;String&#39; - The argument type 'List<string>' can't be assigned to the parameter type 'String' Flutter Firebase 参数类型“对象?” 不能分配给参数类型“地图”<String, dynamic> &#39; - Flutter Firebase The argument type 'Object?' can't be assigned to the parameter type 'Map<String, dynamic>' Flutter Cloud Firestore:错误:参数类型“对象? Function()' 无法分配给参数类型 'Map<string, dynamic> '</string,> - Flutter Cloud Firestore: error: The argument type 'Object? Function()' can't be assigned to the parameter type 'Map<String, dynamic>'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM