import 'package:flutter/material.dart'; import 'package:flutter_hooks/flutter_hooks.dart'; import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart'; PagingController usePagingController({ required final PageKeyType firstPageKey, final int? invisibleItemsThreshold, List? keys, }) { return use( _PagingControllerHook( firstPageKey: firstPageKey, invisibleItemsThreshold: invisibleItemsThreshold, keys: keys, ), ); } class _PagingControllerHook extends Hook> { const _PagingControllerHook({ required this.firstPageKey, this.invisibleItemsThreshold, List? keys, }) : super(keys: keys); final PageKeyType firstPageKey; final int? invisibleItemsThreshold; @override HookState, Hook>> createState() => _PagingControllerHookState(); } class _PagingControllerHookState extends HookState< PagingController, _PagingControllerHook> { late final controller = PagingController( firstPageKey: hook.firstPageKey, invisibleItemsThreshold: hook.invisibleItemsThreshold); @override PagingController build(BuildContext context) => controller; @override void dispose() => controller.dispose(); @override String get debugLabel => 'usePagingController'; }