api - 单击颤动时将数据添加到列表视图
问题描述
我的应用程序中有一个列表视图。当我单击项目时,如果项目有任何数据,我想要显示公司名称,如果没有数据,我想保存选定的项目并移至下一页。如果有数据我想打开我的卡并将其显示为列表。(同页)我怎样才能让它根据公司名称开卡?是否可以在 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。
您可以在要扩展卡时添加详细信息吗?
推荐阅读
- r - 使用 runif() 和 rbern() 的 R 脚本
- c# - 在 Xamarin 表单中隐藏/显示文本
- javascript - 两个 Material-UI 单选按钮都被选中
- nlp - 规范化 Fasttext 预训练的 Fasttext 词嵌入
- python - 根据术语将带有 URL 的列分类为类别
- prestashop - Prestashop 1.7 仅在添加国家地址后显示运费
- python - 我如何检查来自 python 的用户输入是否已经存在于数据库/表中?
- python - Python 文本/Javascript 如何获取 Json 数据?
- javascript - 将删除类部分添加到现有的事件监听器循环
- laravel - Laravel Fortify Return Inertia::render() 而不是刀片视图