首页 > 解决方案 > 单击颤动时将数据添加到列表视图

问题描述

我的应用程序中有一个列表视图。当我单击项目时,如果项目有任何数据,我想要显示公司名称,如果没有数据,我想保存选定的项目并移至下一页。如果有数据我想打开我的卡并将其显示为列表。(同页)我怎样才能让它根据公司名称开卡?是否可以在 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();
                  }
                },
              ),
            ),
          ),
        ],
      ),
    );
  }
}

标签: apiflutterlistview

解决方案


要随时添加小部件,您可以直接将文档添加到 firebase,并使用 StreamBuilder 而不是 FutureBuilder。

您可以在要扩展卡时添加详细信息吗?


推荐阅读