✨ Extended refresh indicator (keyboard based)
This commit is contained in:
@@ -12,6 +12,7 @@ import 'package:island/widgets/content/sheet.dart';
|
||||
import 'package:island/widgets/response.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:styled_widget/styled_widget.dart';
|
||||
import 'package:island/widgets/extended_refresh_indicator.dart';
|
||||
|
||||
part 'account_devices.g.dart';
|
||||
|
||||
@@ -177,7 +178,7 @@ class AccountSessionSheet extends HookConsumerWidget {
|
||||
titleText: 'authSessions'.tr(),
|
||||
child: authDevices.when(
|
||||
data:
|
||||
(data) => RefreshIndicator(
|
||||
(data) => ExtendedRefreshIndicator(
|
||||
onRefresh:
|
||||
() => Future.sync(() => ref.invalidate(authDevicesProvider)),
|
||||
child: ListView.builder(
|
||||
|
67
lib/widgets/extended_refresh_indicator.dart
Normal file
67
lib/widgets/extended_refresh_indicator.dart
Normal file
@@ -0,0 +1,67 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
class RefreshIntent extends Intent {
|
||||
const RefreshIntent();
|
||||
}
|
||||
|
||||
class ExtendedRefreshIndicator extends StatefulWidget {
|
||||
final Widget child;
|
||||
final RefreshCallback onRefresh;
|
||||
|
||||
const ExtendedRefreshIndicator({
|
||||
super.key,
|
||||
required this.child,
|
||||
required this.onRefresh,
|
||||
});
|
||||
|
||||
@override
|
||||
State<ExtendedRefreshIndicator> createState() =>
|
||||
_ExtendedRefreshIndicatorState();
|
||||
}
|
||||
|
||||
class _ExtendedRefreshIndicatorState extends State<ExtendedRefreshIndicator> {
|
||||
late final FocusNode _focusNode;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_focusNode = FocusNode();
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_focusNode.requestFocus();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_focusNode.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Shortcuts(
|
||||
shortcuts: <LogicalKeySet, Intent>{
|
||||
LogicalKeySet(LogicalKeyboardKey.control, LogicalKeyboardKey.keyR):
|
||||
const RefreshIntent(),
|
||||
LogicalKeySet(LogicalKeyboardKey.meta, LogicalKeyboardKey.keyR):
|
||||
const RefreshIntent(),
|
||||
LogicalKeySet(LogicalKeyboardKey.f5): const RefreshIntent(),
|
||||
},
|
||||
child: Actions(
|
||||
actions: <Type, Action<Intent>>{
|
||||
RefreshIntent: CallbackAction<RefreshIntent>(
|
||||
onInvoke: (RefreshIntent intent) => widget.onRefresh(),
|
||||
),
|
||||
},
|
||||
child: Focus(
|
||||
focusNode: _focusNode,
|
||||
child: RefreshIndicator(
|
||||
onRefresh: widget.onRefresh,
|
||||
child: widget.child,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@@ -12,6 +12,7 @@ import 'package:material_symbols_icons/symbols.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:styled_widget/styled_widget.dart';
|
||||
import 'package:flutter_popup_card/flutter_popup_card.dart';
|
||||
import 'package:island/widgets/extended_refresh_indicator.dart';
|
||||
|
||||
part 'picker.g.dart';
|
||||
|
||||
@@ -208,7 +209,7 @@ class _PackSwitcherState extends State<_PackSwitcher> {
|
||||
|
||||
// Content
|
||||
Expanded(
|
||||
child: RefreshIndicator(
|
||||
child: ExtendedRefreshIndicator(
|
||||
onRefresh: widget.onRefresh,
|
||||
child: _StickersGrid(
|
||||
pack: selectedPack,
|
||||
|
Reference in New Issue
Block a user