Skip to content

Commit bea51cd

Browse files
committed
feat: add pull to refresh allow hook
1 parent 6e686ad commit bea51cd

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

lib/app_scaffolds/app.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class App<T> extends StatelessWidget {
2828
static AppEvents? _events;
2929
static AppEvents get events => App._events ?? (throw Exception('App.events is not set. Are you accessing it before the App is built?'));
3030

31+
final Key _keyAppLoader = GlobalKey();
32+
3133
final GalaxyConfig configuration;
3234
final StringBuilder buildTitle;
3335
final ThemeBuilder buildTheme;
@@ -82,6 +84,7 @@ class App<T> extends StatelessWidget {
8284
{
8385
return AppLoader<_GeneratedAppData>(
8486
loadApp: _loadApp,
87+
key: _keyAppLoader,
8588
buildApp: (context, data) => _AppWidget(
8689
buildTitle: buildTitle,
8790
buildTheme: buildTheme,
@@ -153,19 +156,23 @@ class _AppWidget extends StatelessWidget {
153156
});
154157

155158
final Key _keyGlues = GlobalKey();
159+
final Key _keyEasyLocalization = GlobalKey();
160+
final Key _keyNavigationWrapper = GlobalKey();
156161
// final GlobalKey<NavigatorState> _shellNavigatorKey = GlobalKey<NavigatorState>();
157162

158163
@override
159164
Widget build(BuildContext context)
160165
{
161166
return EasyLocalization(
167+
key: _keyEasyLocalization,
162168
path: translationsFolder,
163169
supportedLocales: supportedLocales,
164170
fallbackLocale: fallbackLocale,
165171
child: InsertGlues(
166172
key: _keyGlues,
167173
glues: globalGlues,
168174
child: _NavigationWrapper(
175+
key: _keyNavigationWrapper,
169176
buildTitle: buildTitle,
170177
buildTheme: buildTheme,
171178
generatedData: generatedData,
@@ -183,6 +190,7 @@ class _NavigationWrapper extends StatefulWidget {
183190
final _GeneratedAppData? generatedData;
184191

185192
const _NavigationWrapper({
193+
super.key,
186194
required this.buildTitle,
187195
required this.buildTheme,
188196
required this.generatedData,
@@ -194,6 +202,8 @@ class _NavigationWrapper extends StatefulWidget {
194202

195203
class _NavigationWrapperState extends State<_NavigationWrapper> with WidgetsBindingObserver {
196204

205+
final Key _keyMaterialApp = GlobalKey();
206+
197207
@override
198208
void initState()
199209
{
@@ -221,6 +231,7 @@ class _NavigationWrapperState extends State<_NavigationWrapper> with WidgetsBind
221231
Widget build(BuildContext context)
222232
{
223233
Widget child = MaterialApp.router(
234+
key: _keyMaterialApp,
224235
debugShowCheckedModeBanner: App.config.hideDebugFlag == false,
225236
localizationsDelegates: context.localizationDelegates,
226237
supportedLocales: context.supportedLocales,

lib/cached_query/infinit_query_list.dart

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class InfinitQueryList<T> extends StatefulWidget {
1515
final bool reverse;
1616
final bool shrinkWrap;
1717
final bool disablePullToRefresh;
18+
final bool Function(BuildContext context)? onAllowPullToRefresh;
1819
final List<T> Function(List<T> items)? onTransformItems;
1920

2021
const InfinitQueryList({
@@ -28,6 +29,7 @@ class InfinitQueryList<T> extends StatefulWidget {
2829
this.reverse = false,
2930
this.shrinkWrap = false,
3031
this.disablePullToRefresh = false,
32+
this.onAllowPullToRefresh,
3133
this.onTransformItems,
3234
});
3335

@@ -61,7 +63,16 @@ class _InfinitQueryListState<T> extends State<InfinitQueryList<T>> {
6163

6264
return RefreshIndicator(
6365
backgroundColor: context.colors.surface,
64-
onRefresh: () => query.refetchByUser(),
66+
onRefresh: () async
67+
{
68+
if (widget.onAllowPullToRefresh != null && !widget.onAllowPullToRefresh!(context))
69+
{
70+
await 400.randomize(startValue: 200).delay();
71+
return;
72+
}
73+
74+
await query.refetchByUser();
75+
},
6576
child: _buildContent(context, state, query)
6677
);
6778
}

0 commit comments

Comments
 (0)