jonataslaw / getx

Open screens/snackbars/dialogs/bottomSheets without context, manage states and inject dependencies easily with Get.
MIT License
10.38k stars 1.62k forks source link

SliverList not updating #1427

Open Urkman opened 3 years ago

Urkman commented 3 years ago

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 commented 3 years ago

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

LucaJeevanjee commented 2 years ago

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

waqadArshad commented 2 years ago

@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?

LucaJeevanjee commented 2 years ago

@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.

waqadArshad commented 2 years ago

@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.

LucaJeevanjee commented 2 years ago

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

waqadArshad commented 2 years ago

@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.

tagorenathv commented 1 year ago

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

bgoncharuck commented 1 year ago

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