首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >类'List<Student>‘没有实例getter 'values’。接收方:'_GrowableList‘的实例(长度:11)尝试调用:值

类'List<Student>‘没有实例getter 'values’。接收方:'_GrowableList‘的实例(长度:11)尝试调用:值
EN

Stack Overflow用户
提问于 2020-12-10 14:42:41
回答 1查看 596关注 0票数 0

这是我在flutter中从sqflite获取数据的代码,但在这样做时,我得到了以下错误:

Class 'List<Student>' has no instance getter 'values'. Receiver: Instance(length:11) of '_GrowableList' Tried calling: values

代码语言:javascript
运行
复制
DBHelper dbHelper;
Future<List<Student>> students;

 FutureBuilder(
                future:students,

                builder: (  context,   snapshot) {

                  if (snapshot.hasData) {
                 List<Student> lst = new List<Student>();
                    for (var value in snapshot.data.values){
                      lst.add(value);
                    }
                    return Center(
                      child:
                        //Text('{$snapshot.data.values.toList()[0]["name"]}')

                      InfoCard(

                        title:snapshot.data.values.toList()[0]["name"] ,//snapshot.data.documents[0].toString(),// snapshot.data.values.toList()[0]["name"],
                        iconColor: Color(0xFFFF8C00),
                        effectedNum: '1062',
                        press: () {},
                      ),
                    );
                  } else {
                    return Center(
                      child: CircularProgressIndicator(),
                    );
                  }
                },
              ),
EN

回答 1

Stack Overflow用户

发布于 2020-12-10 15:12:16

这是因为snapshot.data本身就是一个列表,所以不需要.values.toList()属性。所以,去掉那部分就行了。

代码语言:javascript
运行
复制
DBHelper dbHelper;
Future<List<Student>> students;

 FutureBuilder(
                future:students,

                builder: (  context,   snapshot) {

                  if (snapshot.hasData) {
                 List<Student> lst = new List<Student>();
                    for (var value in snapshot.data){
                      lst.add(value);
                    }
                    return Center(
                      child:
                        //Text('{$snapshot.data[0]["name"]}')

                      InfoCard(

                        title:snapshot.data[0]["name"] as String, //snapshot.data.documents[0].toString(),// snapshot.data.values.toList()[0]["name"],
                        iconColor: Color(0xFFFF8C00),
                        effectedNum: '1062',
                        press: () {},
                      ),
                    );
                  } else {
                    return Center(
                      child: CircularProgressIndicator(),
                    );
                  }
                },
              ),
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65229644

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档