【问题标题】:The argument type 'x' can't be assigned to the parameter type 'y'参数类型“x”不能分配给参数类型“y”
【发布时间】:2019-06-03 15:04:47
【问题描述】:

这条线有问题

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();
            }),
      )),
    )

参数类型x不能赋值给参数类型y

【问题讨论】:

  • isPause 返回的是什么?

标签: json flutter dart


【解决方案1】:

您的isPause 没有返回String,它需要返回String,因为Text() 接受String,为了快速破解,您可以尝试以下解决方案。

Text(snapshot.data.isPause.toString());

【讨论】:

  • 在我的手机中,应用程序说 -> type'_InternalLinkedHashMap' 不是子类型 'List'。
  • 可以发fetchPost()方法吗?
  • Future fetchPost() async { final response = await http.get("API link"); if (responce.statusCode == 200) { return Post.fromJson(json.decode(responce.body)); } else { throw Exception('加载失败...!'); } }
  • class Post { final bool autoPlay; final bool isPause;最终列表正在播放;最终列表队列;最终双卷; Post({ this.autoPlay, this.isPause, this.nowPlaying, this.queue, this.volume, });工厂 Post.fromJson(Map json) { return Post( autoPlay: json['auto_play'], isPause: json['is_pause'], nowPlaying: json['now_playing'], queue: json['queue '], 音量: json['volume'], ); } }
  • @Sadisha 请更新您的问题。你能看懂注释代码吗?
猜你喜欢
  • 1970-01-01
  • 2020-04-25
  • 2019-01-27
  • 1970-01-01
  • 2021-03-02
  • 2021-04-09
  • 2016-04-16
  • 2018-02-09
  • 1970-01-01
相关资源
最近更新 更多