颤振快照为空

时间:2021-03-19 14:47:55

标签: flutter dart

我尝试使用 FutureBuilder 在 Flutter 中的 ListView 中显示来自 JSON 的结果。但是快照为空,显示无数据信息

Widget getBody() {
        return Scaffold(
          body: Container(
              padding: EdgeInsets.only(left: 16, top: 1, right: 16),
              child: FutureBuilder<List<dynamic>>(
                  future: getprofile(widget.id),
                  builder: (context, AsyncSnapshot<List<dynamic>> snapshot) {
                    //  String name = snapshot.data['name'];
                    // print(snapshot);
                    List<dynamic> data = snapshot.data;
                    inspect(snapshot);
                    if (snapshot.hasData) {
                      return ListView(
                        children: [
                          Container(
                              decoration: BoxDecoration(
                                  gradient: LinearGradient(
                                      begin: Alignment.topCenter,
                                      end: Alignment.bottomCenter,
                                      colors: [Colors.white, Colors.white])),
                              child: Container(
                                width: double.infinity,
                                height: 350.0,
                                child: Center(
                                  child: Column(
                                    crossAxisAlignment: CrossAxisAlignment.center,
                                    mainAxisAlignment: MainAxisAlignment.center,
                                

 @override
          void initState() {
            getprofile(widget.id);
            super.initState();
          }
        
          Future<List<dynamic>> getprofile(int id) async {
            var response = await Network().getData('/auth/user/$id');
        
            var data = json.decode(response.body)['user'];
          
            return data;
          }

如何显示变量?

enter image description here

0 个答案:

没有答案