mirror of
https://github.com/gabehf/Fladder.git
synced 2026-03-08 23:18:16 -07:00
Init repo
This commit is contained in:
commit
764b6034e3
566 changed files with 212335 additions and 0 deletions
40
lib/util/refresh_state.dart
Normal file
40
lib/util/refresh_state.dart
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
class RefreshState extends InheritedWidget {
|
||||
final GlobalKey<RefreshIndicatorState> refreshKey;
|
||||
final bool refreshAble;
|
||||
|
||||
const RefreshState({
|
||||
super.key,
|
||||
required this.refreshKey,
|
||||
this.refreshAble = true,
|
||||
required super.child,
|
||||
});
|
||||
|
||||
Future<void> refresh() async {
|
||||
if (refreshAble) return await refreshKey.currentState?.show();
|
||||
return;
|
||||
}
|
||||
|
||||
static RefreshState? maybeOf(BuildContext context) {
|
||||
return context.dependOnInheritedWidgetOfExactType<RefreshState>();
|
||||
}
|
||||
|
||||
static RefreshState of(BuildContext context) {
|
||||
final RefreshState? result = maybeOf(context);
|
||||
return result!;
|
||||
}
|
||||
|
||||
@override
|
||||
bool updateShouldNotify(RefreshState oldWidget) {
|
||||
return refreshKey != oldWidget.refreshKey;
|
||||
}
|
||||
}
|
||||
|
||||
extension RefreshContextExtension on BuildContext {
|
||||
Future<void> refreshData() async {
|
||||
//Small delay to fix server not updating response based on successful query
|
||||
await Future.delayed(const Duration(milliseconds: 250));
|
||||
await RefreshState.maybeOf(this)?.refresh();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue