Flutter 弗利特:为什么未来建筑商不';无法运行snapshot.hasData中的内容?编辑

Flutter 弗利特:为什么未来建筑商不';无法运行snapshot.hasData中的内容?编辑,flutter,dart,future,builder,Flutter,Dart,Future,Builder,我制作了许多测试应用程序,但这次我不知道为什么会出现以下错误: 我在无状态小部件中使用Future builder实现了这个Future函数: Future<List> getDegrees() async { var url = 'https://xxxxxx/api/controller/activities/activiy_list.php?d_id=$dId&m_id=$courseId&u_id=$uId'; v

我制作了许多测试应用程序,但这次我不知道为什么会出现以下错误: 我在无状态小部件中使用Future builder实现了这个Future函数:

Future<List> getDegrees() async {
      var url =
          'https://xxxxxx/api/controller/activities/activiy_list.php?d_id=$dId&m_id=$courseId&u_id=$uId';

      var response = await http.get(url);

      var data = jsonDecode(response.body);
      for (var x in data) {
        Digree newdigree = Digree(
            x['index'],
            x['title_k'],
            x['title_a'],
            x['aya'],
            x['link'],
            x['activity_k'],
            x['activity_a'],
            x['act_id'],
            x['mydigree']);
        digrees.add(newdigree);
      }
      return digrees;
    }

    return FutureBuilder(
        future: getDegrees(),
        // ignore: missing_return
        builder: (context, snapshot) {
          if (snapshot.hasError || snapshot.data == null) {
            return WillPopScope(
                // ignore: missing_return
                onWillPop: () async {
                  Navigator.of(context)
                      .pushReplacementNamed('weeks', arguments: {
                    'courseId': courseId,
                  });
                },
                child: Scaffold(
                    appBar: AppBar(
                      backgroundColor: Colors.pink[900],
                      title: Text(
                        'ژیان و قورئان',
                        style: TextStyle(fontSize: 32),
                      ),
                      centerTitle: true,
                    ),
                    body: Container(
                      height: MediaQuery.of(context).size.height,
                      width: MediaQuery.of(context).size.width,
                      decoration: BoxDecoration(
                          image: DecorationImage(
                              image:
                                  AssetImage('./assets/images/background.png'),
                              fit: BoxFit.cover)),
                      child: Column(
                        children: [
                          SizedBox(
                            height: 100,
                          ),
                          Container(
                            height: 100,
                            width: 100,
                            child: CircularProgressIndicator(
                              backgroundColor: Colors.black,
                              strokeWidth: 5,
                            ),
                          ),
                          SizedBox(
                            height: 20,
                          ),
                          Text(
                            "Loading ......",
                            style: TextStyle(color: Colors.white, fontSize: 18),
                          )
                        ],
                      ),
                    )));
          } else if (snapshot.hasData) {
            return WillPopScope(
                // ignore: missing_return
                onWillPop: () async {
                  Navigator.of(context)
                      .pushReplacementNamed('weeks', arguments: {
                    'courseId': courseId,
                  });
                },
                child: Scaffold(body: Container(child: Text('welcome'))));
          }
        });
Future getDegrees()异步{
变量url=
'https://xxxxxx/api/controller/activities/activiy_list.php?d_id=$dId&m_id=$courseId&u_id=$uId';
var response=wait http.get(url);
var data=jsonDecode(response.body);
用于(数据中的var x){
Digree newdigree=Digree(
x[“索引”],
x['title_k'],
x['title_a'],
x['aya'],
x[“链接”],
x['activity_k'],
x['activity_a'],
x['act_id'],
x['mydigree']);
digrees.add(newdigree);
}
返回digrees;
}
回归未来建设者(
future:getDegrees(),
//忽略:缺少返回
生成器:(上下文,快照){
if(snapshot.hasError | | snapshot.data==null){
返回式示波器(
//忽略:缺少返回
onWillPop:()异步{
导航器(上下文)
.pushReplacementNamed('weeks',参数:{
“courseId”:courseId,
});
},
孩子:脚手架(
appBar:appBar(
背景颜色:颜色。粉红色[900],
标题:正文(
'ژیان و قورئان',
样式:TextStyle(字体大小:32),
),
标题:对,
),
主体:容器(
高度:MediaQuery.of(context).size.height,
宽度:MediaQuery.of(context).size.width,
装饰:盒子装饰(
图像:装饰图像(
图片:
AssetImage('./assets/images/background.png'),
安装:BoxFit.盖),
子:列(
儿童:[
大小盒子(
身高:100,
),
容器(
身高:100,
宽度:100,
子对象:循环压缩机指示器(
背景颜色:Colors.black,
冲程宽度:5,
),
),
大小盒子(
身高:20,
),
正文(
“装载……”,
样式:TextStyle(颜色:Colors.white,字体大小:18),
)
],
),
)));
}else if(snapshot.hasData){
返回式示波器(
//忽略:缺少返回
onWillPop:()异步{
导航器(上下文)
.pushReplacementNamed('weeks',参数:{
“courseId”:courseId,
});
},
孩子:脚手架(身体:容器(孩子:文本('welcome'));
}
});
我检查了很多次没有发现错误,当我在函数中打印收到的列表时,它被正确打印,但是当我在将来的生成器中显示它时,它不工作,我的问题在哪里

问题是:Future Builder只运行CircularProgressIndicator。
有什么帮助吗?请发布完整的错误不要用
ignore:missing\u return
隐藏返回错误。该警告告诉您应该返回某些内容的方法并不总是返回某些内容。例如,在您的
FutureBuilder
中,当
snapshot.hasError | snapshot.data==null
snapshot.hasData
时,它将返回一些内容,但如果这些内容都不为真,则该构建方法将不会返回任何内容,这将导致抖动错误。警告是有原因的,除非你有很好的理由,否则不要隐藏它们。对不起,我可以更改我的问题吗谢谢你,我在问题中做了更改,你正确打印了哪些列表,
数据
digrees