riverpod_infinite_scroll_page 0.0.3 copy "riverpod_infinite_scroll_page: ^0.0.3" to clipboard
riverpod_infinite_scroll_page: ^0.0.3 copied to clipboard

This project is a sample Flutter application demonstrating infinite scrolling pagination using Riverpod for state management. It builds on the infinite_scroll_pagination package and includes optimizat [...]

0.0.3 #

Optimize the code and add a persistence provider. Attention! PagedListView must be consistent with MultiItemChildBuilderDelegate persistent persistent

class TestPage extends ConsumerStatefulWidget {
  const TestPage({super.key});

  @override
  ConsumerState<ConsumerStatefulWidget> createState() => _TestPageState();
}

class _TestPageState extends ConsumerState<TestPage> {
  final String pageKey = '0';

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: PagedListView<String, PagingItem>(
        builderDelegate: itemRegister(),
        pagingDataController: TestPageNetWorkController(pageKey),
        statusBuilderDelegate: statusBuilder(),
        persistent: true, // keep data
      ),
      floatingActionButton: FloatingActionButton(onPressed: () {
        final pagingController =
            ref.read(pagingControllerProvider(pageKey).notifier);
        pagingController.updateItemAt(8, TestItem('11111'));
      }),
    );
  }

  PagedChildStatusBuilderDelegate<PagingItem> statusBuilder() {
    return PagedChildStatusBuilderDelegate(
      newPageErrorIndicatorBuilder: (context, retryCallback) {
        return GestureDetector(
          onTap: retryCallback,
          child: const SizedBox(
            height: 40,
            child: Center(child: Text('error')),
          ),
        );
      },
    );
  }

  MultiItemChildBuilderDelegate itemRegister() {
    return MultiItemChildBuilderDelegate(
      pageKey,
      pagingItemRegister: PagingItemRegister(
        itemRegister: {
          TestItem: buildTestItem,
        },
      ),
      persistent: true, //// keep data
    );
  }

  Widget buildTestItem<T extends PagingItem>(
      BuildContext context, T data, int index) {
    print('buildTestItem $index');
    final testItem = data as TestItem; // 假设 TestItem 是具体的类型
    return Text('item $index name${testItem.name}');
  }
}

0.0.1 #

  • TODO: Describe initial release.
1
likes
0
points
25
downloads

Publisher

unverified uploader

Weekly Downloads

This project is a sample Flutter application demonstrating infinite scrolling pagination using Riverpod for state management. It builds on the infinite_scroll_pagination package and includes optimizations to avoid unnecessary rebuilds. Specifically, it prevents the entire list from being rebuilt when only specific items need updating, resulting in improved performance for large lists.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, flutter_riverpod, flutter_staggered_grid_view, sliver_tools, tuple

More

Packages that depend on riverpod_infinite_scroll_page