Sqlite 如何在颤振中用for循环替换卡
我想用for-loop替换这张卡。这是我的屏幕主体,我在这里显示输出Sqlite 如何在颤振中用for循环替换卡,sqlite,flutter,dart,card,Sqlite,Flutter,Dart,Card,我想用for-loop替换这张卡。这是我的屏幕主体,我在这里显示输出 body: FutureBuilder<List> ( future: db.getAllRecords("EMPLOYEE"), initialData: List(), builder: (context,snapshot){ return snapshot.hasData ? L
body: FutureBuilder<List>
(
future: db.getAllRecords("EMPLOYEE"),
initialData: List(),
builder: (context,snapshot){
return snapshot.hasData
? ListView.builder(
itemCount: snapshot.data.length,
itemBuilder: (_, int position){
final item =snapshot.data[position];
return Card(
child:ListTile(
title: Text(
snapshot.data[position].row[1]
),
),
);
},
)
: Center(
child:CircularProgressIndicator() ,
);
body:FutureBuilder
(
未来:db.getAllRecords(“员工”),
initialData:List(),
生成器:(上下文,快照){
返回snapshot.hasData
?ListView.builder(
itemCount:snapshot.data.length,
itemBuilder:(_,int位置){
最终项目=快照数据[位置];
回程卡(
孩子:ListTile(
标题:正文(
快照.数据[位置].行[1]
),
),
);
},
)
:中心(
子对象:CircularProgressIndicator(),
);
实际上,您编写它的方式是颤振中的标准实现方式。您可以调用默认的ListView
构造函数,而不是ListView.builder
one,然后调用for循环,但这不是最佳做法
List<Widget> _buildListItems(BuildContext context, List<...> list) {
final output = List<Widget>();
for (var item in list) {
output.add(
Card(
child: ListTile(
title: Text(item.row[1]),
),
),
);
}
return output;
}
//... back to your build(context) body
body: FutureBuilder<List>(
future: db.getAllRecords("EMPLOYEE"),
builder: (context, snapshot) {
return snapshot.hasData
? ListView(
children: [
..._buildListItems(context, snapshot.data),
],
)
: Center(
child: CircularProgressIndicator(),
);
}
)
List\u buildListItems(BuildContext上下文,列表){
最终输出=列表();
用于(列表中的var项){
output.add(
卡片(
孩子:ListTile(
标题:文本(项目行[1]),
),
),
);
}
返回输出;
}
//…返回到构建(上下文)主体
正文:未来建设者(
未来:db.getAllRecords(“员工”),
生成器:(上下文,快照){
返回snapshot.hasData
?列表视图(
儿童:[
…_buildListItems(上下文、snapshot.data),
],
)
:中心(
子对象:CircularProgressIndicator(),
);
}
)
好吧,我将用信用卡向那个些人数(最多5人)的员工发送短信。我不能这样做。还有其他方法吗?你们的评论似乎是一个完全不同的问题,和用户界面无关。你们可以用它发送短信。我建议发布一个新问题,详细说明你们想要实现的目标。