Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 如何使用';未来<;动态>';作为json(映射)_Flutter_Dart - Fatal编程技术网

Flutter 如何使用';未来<;动态>';作为json(映射)

Flutter 如何使用';未来<;动态>';作为json(映射),flutter,dart,Flutter,Dart,我通过API获取json数据并解码为 Map 然后在FutureBuilder中使用此选项,但它不起作用 child: FutureBuilder<dynamic>( future: mixItems, builder: (context, snapshot) { if (snapshot.hasData) { print("snapshot has arrived!"); p

我通过API获取json数据并解码为
Map

然后在
FutureBuilder
中使用此选项,但它不起作用

    child: FutureBuilder<dynamic>(
      future: mixItems,
      builder: (context, snapshot) {
        if (snapshot.hasData) {
          print("snapshot has arrived!");
          print(mixItems);
          print(mixItems[0]);// it shows error.
          return Text(mixItems[0]);
        }
        return CircularProgressIndicator();
      },
    )
child:FutureBuilder(
未来:混合项目,
生成器:(上下文,快照){
if(snapshot.hasData){
打印(“快照已到达!”);
打印(项目);
打印(mixItems[0]);//显示错误。
返回文本(混合项[0]);
}
返回循环ProgressIndicator();
},
)
但是,print(mixItems[0])显示错误

lib/main.dart:115:29:错误:未为类“Future”定义运算符“[]”


如何修复它???

将json转换为对象列表
class _MyHomePageState extends State<MyHomePage> {
  Future<dynamic> mixItems;
  @override
  void initState() {
    super.initState();
    mixItems = fetchMix();
  }
    child: FutureBuilder<dynamic>(
      future: mixItems,
      builder: (context, snapshot) {
        if (snapshot.hasData) {
          print("snapshot has arrived!");
          print(mixItems);
          print(mixItems[0]);// it shows error.
          return Text(mixItems[0]);
        }
        return CircularProgressIndicator();
      },
    )