Document `useRefreshable` hook

This commit is contained in:
shilangyu 2021-01-09 17:25:34 +00:00
parent 0d434fafcc
commit a994d7ca30
2 changed files with 8 additions and 4 deletions

View File

@ -13,6 +13,13 @@ class Refreshable<T> {
final AsyncCallback refresh;
}
/// Similar to [useMemoFuture] but adds a `.refresh` method which
/// allows to re-run the fetcher. Calling `.refresh` will not
/// turn AsyncSnapshot into a loading state. Instead it will
/// replace the ready state with the new data when available
///
/// `keys` will re-run the initial fetching thus yielding a
/// loading state in the AsyncSnapshot
Refreshable<T> useRefreshable<T>(AsyncValueGetter<T> fetcher,
[List<Object> keys = const <dynamic>[]]) {
final newData = useState<T>(null);

View File

@ -28,10 +28,8 @@ class InfiniteScroll<T> extends HookWidget {
final InfiniteScrollController controller;
final Widget prepend;
final EdgeInsetsGeometry padding;
final GlobalKey<RefreshIndicatorState> _refreshIndicatorKey =
GlobalKey<RefreshIndicatorState>();
InfiniteScroll({
const InfiniteScroll({
this.batchSize = 10,
this.prepend = const SizedBox.shrink(),
this.padding,
@ -65,7 +63,6 @@ class InfiniteScroll<T> extends HookWidget {
final page = data.value.length ~/ batchSize + 1;
return RefreshIndicator(
key: _refreshIndicatorKey,
onRefresh: () async {
controller.clear();
await HapticFeedback.mediumImpact();