getx icon indicating copy to clipboard operation
getx copied to clipboard

SliverList not updating

Open Urkman opened this issue 3 years ago • 7 comments

The SliverList is not updating without clearing it first before the request. But with clearing the list, we get an ugly empty screen for some milliseconds :(

I use this code (shortend):

page:

    @override
    Widget build(BuildContext context) {
        return Container(
          decoration: BoxDecoration(
            color: AppColors.background(context),
          ),
          child: Obx(
          () => CustomScrollView(
            slivers: <Widget>[
              SliverList(
                delegate: _delegate,
              ),
            ],
          ),
        ),
      );

delegate:

  SliverChildBuilderDelegate get _delegate => SliverChildBuilderDelegate(
        (context, index) {
          return Padding(
            padding: const EdgeInsets.fromLTRB(8, 8, 8, 8),
            child: ItemView(
              item: Get.find<ListController>().itemsList[index],
            ),
          );
        },
        childCount: Get.find< ListController >().itemsList.length,
      );

controller:

  void fetchData() async {
    try {
      isLoading.value = true;
      // itemsList.clear(); <- this makes the difference. Uncommenting this makes it work
      var items = await _fetchDataRequest(someId);
      if (items != null) {
        itemsList.value = items;
      }
    } finally {
      isLoading.value = false;
    }
  }

Is there a way to get it working without clearing the list?

And by the way. Is there a difference in this code:

1.) itemsList.value = items;
2.) itemsList(items);

Thanks, Urkman

Urkman avatar May 13 '21 06:05 Urkman

It turns out, that not even clearing the list always helps to update the SilverList :(

Urkman avatar May 13 '21 09:05 Urkman

Any updates, really need this for my chat message list...

LucaJeevanjee avatar Jun 11 '22 15:06 LucaJeevanjee

@Urkman yes please, we need a solution. even my box can not rebuild the list. also, @LucaJeevanjee @jonataslaw @jasonlaw did any of you find a solution?

waqadArshad avatar Jul 06 '22 12:07 waqadArshad

@Urkman yes please, we need a solution. even my box can not rebuild the list. also, @LucaJeevanjee @jonataslaw @jasonlaw did any of you find a solution?

Hey, I'm away right now but if I remember correctly you could try wrapping your list items with an object key, for some reason that let mine rebuild.

LucaJeevanjee avatar Jul 06 '22 13:07 LucaJeevanjee

@Urkman yes please, we need a solution. even my box can not rebuild the list. also, @LucaJeevanjee @jonataslaw @jasonlaw did any of you find a solution?

Hey, I'm away right now but if I remember correctly you could try wrapping your list items with an object key, for some reason that let mine rebuild.

@LucaJeevanjee have never used it before. so please do share some code when you can. thanks.

waqadArshad avatar Jul 06 '22 13:07 waqadArshad

key:ObjectKey('randomindex'), child:Container()

LucaJeevanjee avatar Jul 06 '22 13:07 LucaJeevanjee

@LucaJeevanjee Hi, Thanks for this. I tried but I guess for me the problem is that I am using a stream with GetX and streams do not work very well with GetX and that is what's causing an issue. Please do let me know if you have any solution for that.

waqadArshad avatar Jul 06 '22 20:07 waqadArshad

Facing same issue with Obx & SliverList. Any update on this?

tagorenathv avatar Jan 04 '23 16:01 tagorenathv

ObjectKey is working for me to. Maybe add this to GetX documentation?

bgoncharuck avatar Jun 20 '23 18:06 bgoncharuck