Home > Mobile >  How to get itemcount data from ListView and share to any other pages/widgets?
How to get itemcount data from ListView and share to any other pages/widgets?

Time:01-10

I am new in flutter I want to show the itemcount data from Streambuilder listview builder to the dashboard of another widget. Please help

My file inside listview.dart is:

 Flexible(
     child: StreamBuilder(
            stream: DatabaseManager.orderStream(isAscending),
            builder: (context, AsyncSnapshot<QuerySnapshot> snapshot) {
                     final value = snapshot.data!.docs;
                     return value.isEmpty
                              ? const Center(
                                   child: Text(AppString.noAvailableOrder),
                                      )
                                    : ListView.builder(
                                        itemCount: value.length,
                                        itemBuilder: (context, i) => OrderListData(
                                              id: value[i].id,
                                              location: value[i]["recLocation"],
                                              phoneNo: value[i]["recPhone"],
                                              recName: value[i]["recName"],
                                            ),
                                          );
                                       },
                                     ),
                                  ),
                                ],
                             ),
                         );
                       }
           
                     },
               );
         }

I want to show item count data in dashboard.dart :

CodePudding user response:

I think you should declare final value before the @override Widget like var value and then in the Steam builder write setState(() => value = snapshot.data!.docs). Now you can use value while pushing in the navigator.

CodePudding user response:

You have to call init()function on dashboard.dart for retrieving the length of data,which will be available by futurebuilder in utils.dart(All dbhelpers and builders are written here) file. Then For intial data retrieval make a seperate file for Futurebuilders and retrieve data by variable. Or you can intialize Futurebuilder in main.dart also which is basically good method.

  •  Tags:  
  • Related