Json 参数类型';x';can';不能分配给参数类型';y';
这条线路有问题Json 参数类型';x';can';不能分配给参数类型';y';,json,flutter,dart,Json,Flutter,Dart,这条线路有问题 Text(snapshot.data.isPause); 我不知道怎么修理它 -----------------------------------------代码------------------------------------------- MaterialApp( debugShowCheckedModeBanner: false, home: Scaffold( body: Center( child:
Text(snapshot.data.isPause);
我不知道怎么修理它
-----------------------------------------代码-------------------------------------------
MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: FutureBuilder<Post>(
future: fetchPost(),
builder: (context, snapshot) {
if (snapshot.hasData)
return Text(snapshot.data.isPause);
else if (snapshot.hasError) {
return Text("${snapshot.error}");
}
return CircularProgressIndicator();
}),
)),
)
MaterialApp(
debugShowCheckedModeBanner:false,
家:脚手架(
正文:中(
孩子:未来建设者(
future:fetchPost(),
生成器:(上下文,快照){
if(snapshot.hasData)
返回文本(snapshot.data.isPause);
else if(snapshot.hasrerror){
返回文本(“${snapshot.error}”);
}
返回循环ProgressIndicator();
}),
)),
)
参数类型
x
无法分配给参数类型y您的i因为没有返回String
,它需要返回String
,因为Text()
接受String
,为了快速破解,您可以尝试下面的解决方案
Text(snapshot.data.isPause.toString());
isPause
返回的是什么?在我的手机中,应用程序说->键入“InternalLinkedHashMap”不是子类型“List”。你能发布fetchPost()
方法吗?Future fetchPost()异步{final response=wait http.get(“API link”);if(response.statusCode==200){return post.fromJson(json.decode(response.body))}else{throw Exception('Failed to load…!');}}class Post{final bool autoPlay;final bool isPause;final List nowPlaying;final List queue;final double volume;Post({this.autoPlay,this.isPause,this.nowPlaying,this.queue,this.volume,});factory Post.fromJson(Map json){return Post(autoPlay:json['auto_play']、isPause:json['is_pause']、nowPlaying:json['now_playing']、queue:json['queue']、volume:json['volume']、);}}@Sadisha请更新您的问题。您甚至可以阅读注释代码吗?