Home > OS >  Flutter Remove temp List<Model> without removing original list lazyloading
Flutter Remove temp List<Model> without removing original list lazyloading

Time:10-08

Currently I'am learning lazyloading flutter, i have some errors when load _lazlLoadingLoadMore() after endOfPage Lazyloading is triggered. the original List also removed just like templist.

...
list<ModelData> dataList = value.data.length;
...

Future _lazlLoadingLoadMore() async {
setState(() {
  _loading = true;
});

increment = increment   1;

if (increment >= widget.value.data.length) {
  increment = widget.value.data.length;
}

tempList = dataList;
tempList.removeRange(increment, dataList.length);

setState(() {
  _loading = false;
});}

first run

2nd run

CodePudding user response:

you can clear temp list and use addAll/assignAll example

List<String> list = [];
List<String> listAll = [];



list.clear();// or list = [];
list.addAll(listAll);// or list.assignAll(listAll);

then call removeRange

list.removeRange(increment, listAll.length);

CodePudding user response:

You can create new instance like

tempList = dataList.toList();//this
tempList.removeRange(increment, dataList.length);
  • Related