mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-12 23:45:18 +00:00

track Share popup menu not showing when not logged in fix page tranistions changed to default material 3 design's Wrong link in Login page fix Changing UserPreferences provider resets the Playback provider using using hookified_infinite_scroll_pagination officially
43 lines
1.3 KiB
Dart
43 lines
1.3 KiB
Dart
import 'package:flutter_hooks/flutter_hooks.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:hookified_infinite_scroll_pagination/hookified_infinite_scroll_pagination.dart';
|
|
|
|
PagingController<P, ItemType> usePaginatedFutureProvider<T, P, ItemType>(
|
|
FutureProvider<T> Function(P pageKey) createSnapshot, {
|
|
required P firstPageKey,
|
|
required WidgetRef ref,
|
|
void Function(
|
|
T,
|
|
PagingController<P, ItemType> pagingController,
|
|
P pageKey,
|
|
)?
|
|
onData,
|
|
void Function(Object)? onError,
|
|
void Function()? onLoading,
|
|
}) {
|
|
final currentPageKey = useState(firstPageKey);
|
|
final snapshot = ref.watch(createSnapshot(currentPageKey.value));
|
|
final pagingController = usePagingController<P, ItemType>(
|
|
firstPageKey: firstPageKey,
|
|
onPageRequest: (pageKey, pagingController) {
|
|
if (currentPageKey.value != pageKey) {
|
|
currentPageKey.value = pageKey;
|
|
}
|
|
});
|
|
|
|
useEffect(() {
|
|
snapshot.whenOrNull(
|
|
data: (data) =>
|
|
onData?.call(data, pagingController, currentPageKey.value),
|
|
error: (error, _) {
|
|
pagingController.error = error;
|
|
return onError?.call(error);
|
|
},
|
|
loading: onLoading,
|
|
);
|
|
return null;
|
|
}, [currentPageKey, snapshot]);
|
|
|
|
return pagingController;
|
|
}
|