Home > Mobile >  Asserion Problem with ListView.builder. (Expanded widget? shrinkWrap=true?)
Asserion Problem with ListView.builder. (Expanded widget? shrinkWrap=true?)

Time:07-24

currently building an app with flutter. and I have this ListView.builder that gives me an assertion error. I tried to wrap it with an expanded widget or put shrinkwrap=true, but nothing worked. Probably it has to do with the fact that I have a StreamBuilder inside the ListView.builder. Indeed this is the error that I receive.

Failed assertion: line 5186 pos 16: 'child is! ParentDataElement': is not true (referred to the Streambuilder Here is my code for the main page:

 @override
  Widget build(BuildContext context) {
    DateTime now = DateTime.now();
    DateTime date = DateTime(now.year, now.month, now.day);
    return Scaffold(
      backgroundColor: kMainPageColor,
      body: Column(
        children: [
          Container(
                height: 200, child: CardSelection(mycustomFunction: parentIndex)),
         Expanded(
           child: ListView.builder(
                   shrinkWrap: true,
                   itemCount: widget.ListofFirends.length 1,
                    itemBuilder: (context, indexxx) {
                      List<Stream> diffStreamsForDifferentTimesPeriods = [
                    DataBaseService(uid: indexxx==0?widget.uid:widget.ListofFirends[indexxx-1]).personalTimingsofToday,
                    DataBaseService(uid: indexxx==0?widget.uid:widget.ListofFirends[indexxx-1]).personalTimingsYestrday,
                    DataBaseService(uid: indexxx==0?widget.uid:widget.ListofFirends[indexxx-1]).personalTimingsTwoDaysAgo,
                    DataBaseService(uid: indexxx==0?widget.uid:widget.ListofFirends[indexxx-1]).personalTimingsLastWeek,
                  ];
                  return StreamBuilder<dynamic>(
                      stream: diffStreamsForDifferentTimesPeriods[index],
                      builder: (context, snapshot) {
                        if (snapshot.hasData) {
                          UserActionnss? _actionsofToday = snapshot.data;
                          times[index] = [
                            _actionsofToday?.one,
                            _actionsofToday?.two,
                            _actionsofToday?.three,
                            _actionsofToday?.four,
                            _actionsofToday?.five,
                            _actionsofToday?.six,
                            _actionsofToday?.seven,
                            _actionsofToday?.eight
                          ];
                
                          return FormatTImings(
                            TIIMES: times[index],
                          );
                        } else {
                          return Expanded(
                            child: FormatTImings(
                                TIIMES: const [0, 0, 0, 0, 0, 0],
                              ),
                          );
                        }
                      });},
                ),
         ),
           
        ],
      ),
    );
  }
}

CodePudding user response:

You can't return Expanded Widget in Listview.Builder.

return Expanded(
                            child: FormatTImings(
                                TIIMES: const [0, 0, 0, 0, 0, 0],
                              ),
                          );

CodePudding user response:

Do not wrap listview.builder inside an expanded widget. Use an only a container or sized box instead of that.

  • Related