Home > Net >  Flutter how get all data on return List<Widget>?
Flutter how get all data on return List<Widget>?

Time:12-22

I created a widget and I want to return all the data I pulled from firestore there. I want to sort all the data I returned in one page, one under the other, in the Text() widget.

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();
  });
}

CodePudding user response:

You can set items and the children of a Row like so:

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: [Icon(Icons.add), ...items]);
      
    }
    return CircularProgressIndicator();
  });
  • Related