feat: new next_page signature, query/mutation fn in notifier and safe update in use_updater
This commit is contained in:
@@ -26,12 +26,9 @@ class InfiniteQueryPageWidget extends HookWidget {
|
||||
throw ClientException(res.statusCode.toString(), res.request?.url);
|
||||
}
|
||||
},
|
||||
nextPage: (lastPage, pages) {
|
||||
if (pages.isNotEmpty &&
|
||||
pages.last.products.length < pages[lastPage].limit) {
|
||||
/// returning [null] will set [hasNextPage] to [false]
|
||||
return null;
|
||||
}
|
||||
nextPage: (lastPage, lastPageData) {
|
||||
/// returning [null] will set [hasNextPage] to [false]
|
||||
if (lastPageData.products.length < 10) return null;
|
||||
return lastPage + 1;
|
||||
},
|
||||
initialPage: 0,
|
||||
|
||||
@@ -1,10 +1,20 @@
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
|
||||
ValueChanged<dynamic> useUpdater() {
|
||||
final state = useState(false);
|
||||
final isMounted = useIsMounted();
|
||||
return ([_]) {
|
||||
if (isMounted()) state.value = !state.value;
|
||||
return ([_]) async {
|
||||
if (!isMounted()) return;
|
||||
|
||||
// if there's a current frame,
|
||||
if (SchedulerBinding.instance.schedulerPhase != SchedulerPhase.idle) {
|
||||
// wait for the end of that frame.
|
||||
await SchedulerBinding.instance.endOfFrame;
|
||||
if (!isMounted()) return;
|
||||
}
|
||||
|
||||
state.value = !state.value;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user