I have a flutter app where user can add items to a list which are stored in firebase. User can add up to 1000 items at once. Initially this is no issue but with a growing number of list items the app gets slower and slower until when adding multiple items at once after roughly 1000 items are in the list it crashes the app due to the memory use -
thread #10, name = 'io.flutter.1.ui', stop reason = EXC_RESOURCE RESOURCE_TYPE_MEMORY (limit=1450 MB, unused=0x0)
How can I improve the code so the performance improves. I would like to keep the setup with the Stream since it lets me dynamically filter the list on the fly. One information here as well is that WidgetA and WidgetB also both use the Stream Data to display the number of list items in the list.
Here is my code a bit simplified for ease of reading:
Main Screen Class:
Widget content(context) {double h = MediaQuery.of(context).size.height; //screen heightdouble w = MediaQuery.of(context).size.width; //screen widthreturn StreamProvider<List<Activity>>.value( catchError: (_, __) => null, value: DatabaseService().activities(widget.uid), builder: (context, snapshot) { return SafeArea( child: Container( //color: Theme.of(context).backgroundColor, //SkyHookTheme.background, child: Scaffold( backgroundColor: Colors.transparent, body: NotificationListener<ScrollNotification>( onNotification: _handleScrollNotification, child: Stack(children: [ ListView( controller: _scrollController, children: <Widget>[ Column( children: <Widget>[ WidgetA(), WidgetB(), ActivityList(), //List of User Activities ], ) ], ), ]), ), ), ), ); });}
ActivityList Class Listview Building:
ListView buildList(List<Activity> acts){items = ListView.builder( shrinkWrap: true, physics: ClampingScrollPhysics(), scrollDirection: Axis.vertical, itemCount: len, itemBuilder: (context, index) { return ActivityTile(activity: acts[index], number: acts.length - (index)); },);return items;
}
Any Tips / Hints how I can improve this would be highly appreciated.
Thanks!