如何解决单击时将数据添加到列表视图
我的应用中有一个列表视图。当我单击项目时,如果项目有任何数据,则我需要显示公司名称;如果没有数据,我要保存所选的数据并移至下一页。如果有数据,我要打开我的卡并将其显示为列表。 (在同一页上) 如何根据公司名称打开卡?是否可以在Ontap中添加新的小部件?
这是我的代码,
class _CountryScreenState extends State<CountryScreen> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
Padding(
padding: const EdgeInsets.only(top: 12.0),child: Text('Please chose',style: TextStyle(fontWeight: FontWeight.bold,fontSize: 16),),Expanded(
child: Center(
child: FutureBuilder<CountryList>(
future: fetchCountryList(),builder: (BuildContext context,AsyncSnapshot<CountryList> snapshot) {
if (snapshot.hasData) {
return ListView.builder(
itemCount: snapshot.data.data.length,itemBuilder: (BuildContext context,int position) {
return Container(
height: 72,padding: const EdgeInsets.all(10.0),child: Card(
child: InkWell(
onTap: () async {
List<Company> companies= await fetchCompaniesList(snapshot.data.data[position].code);
Navigator.pushNamed(context,MainScreen.routeName);
},child: Row(
children: [
Padding(
padding:
const EdgeInsets.symmetric(horizontal: 8.0),child: Image.asset(
'icons/flags/png/${snapshot.data.data[position].code.toLowerCase()}.png',package: 'country_icons',height: 20,width: 34,Padding(
padding:
const EdgeInsets.symmetric(horizontal: 8.0),child: Text(snapshot.data.data[position].name,style: TextStyle(fontSize: 16),],);
},);
} else {
return CircularProgressIndicator();
}
},);
}
}
解决方法
要在点击时添加小部件,您可以将文档直接添加到firebase中,并使用StreamBuilder代替FutureBuilder。
要扩展卡时可以添加详细信息吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。