dart Flutter如何获得所有数据的回报列表< Widget>?

aurhwmvo  于 2022-12-20  发布在  Flutter
关注(0)|答案(1)|浏览(131)

我创建了一个小部件,我想返回从firestore中提取的所有数据,我想在Text()小部件中对一个页面中返回的所有数据进行排序,一个在另一个下面。

Widget getCustomerRepairLogDate() {
final user = FirebaseAuth.instance.currentUser!;
late final _repairLogs =
  FirebaseFirestore.instance.collection('Repair').get();
return FutureBuilder(
  future: _repairLogs,
  builder: (context, AsyncSnapshot snapshot) {
    if (snapshot.hasData) {
      List<Widget> items = [];
      final data = snapshot.data?.docs;
      if (data == null) return Text("got null");

      for (final eleman in data) {
        if (eleman.data()['email']! == user.email) {
          items.add(Text("${eleman.data()['dateTime']}"));
        }
      }
      return ListView(children: items);
      // return CircularProgressIndicator();
    }
    return CircularProgressIndicator();
  });
}
r7xajy2e

r7xajy2e1#

可以如下设置itemsRowchildren

return FutureBuilder(
  future: _repairLogs,
  builder: (context, AsyncSnapshot snapshot) {
    if (snapshot.hasData) {
      List<Widget> items = [];
      final data = snapshot.data?.docs;
      if (data == null) return Text("got null");

      for (final eleman in data) {
        if (eleman.data()['email']! == user.email) {
          items.add(Text("${eleman.data()['description']}"));
        }
      }
      return Row(children: items);
      
    }
    return CircularProgressIndicator();
  });

相关问题