advanced_list_riverpod icon indicating copy to clipboard operation
advanced_list_riverpod copied to clipboard

Error when reload data

Open phucdth12a opened this issue 2 years ago • 1 comments

But when refresh data or change data with new length less than old length it show error Unhandled Exception: RangeError (index): Invalid value: Only valid value is 0: 1.

phucdth12a avatar Aug 01 '23 01:08 phucdth12a

Can you give me an example code to understand the problem better. Because when I add refresh feature to the app, it worked with no error.

return RefreshIndicator( // Added this line
      onRefresh: () async => ref.invalidate(listProvider),  // Added this line
      child: ListView.builder(
        itemCount: ref.watch(listProvider.select((e) => e.length)),
        itemBuilder: (_, index) {
          return ProviderScope(
            overrides: [indexProvider.overrideWith((_) => index)],
            child: const _ListItem(),
          );
        },
      ), // Added this line
    );

rei-codes avatar Aug 09 '23 22:08 rei-codes