diff --git a/lib/app/models.dart b/lib/app/models.dart index f8a25c03..68e3b39f 100755 --- a/lib/app/models.dart +++ b/lib/app/models.dart @@ -39,7 +39,7 @@ class MenuAction with _$MenuAction { factory MenuAction( {required String text, required Icon icon, - void Function()? action}) = _MenuAction; + void Function(BuildContext context)? action}) = _MenuAction; } @freezed diff --git a/lib/app/models.freezed.dart b/lib/app/models.freezed.dart index 58c09a62..f3245477 100755 --- a/lib/app/models.freezed.dart +++ b/lib/app/models.freezed.dart @@ -655,7 +655,9 @@ class _$MenuActionTearOff { const _$MenuActionTearOff(); _MenuAction call( - {required String text, required Icon icon, void Function()? action}) { + {required String text, + required Icon icon, + void Function(BuildContext)? action}) { return _MenuAction( text: text, icon: icon, @@ -671,7 +673,7 @@ const $MenuAction = _$MenuActionTearOff(); mixin _$MenuAction { String get text => throw _privateConstructorUsedError; Icon get icon => throw _privateConstructorUsedError; - void Function()? get action => throw _privateConstructorUsedError; + void Function(BuildContext)? get action => throw _privateConstructorUsedError; @JsonKey(ignore: true) $MenuActionCopyWith get copyWith => @@ -683,7 +685,7 @@ abstract class $MenuActionCopyWith<$Res> { factory $MenuActionCopyWith( MenuAction value, $Res Function(MenuAction) then) = _$MenuActionCopyWithImpl<$Res>; - $Res call({String text, Icon icon, void Function()? action}); + $Res call({String text, Icon icon, void Function(BuildContext)? action}); } /// @nodoc @@ -712,7 +714,7 @@ class _$MenuActionCopyWithImpl<$Res> implements $MenuActionCopyWith<$Res> { action: action == freezed ? _value.action : action // ignore: cast_nullable_to_non_nullable - as void Function()?, + as void Function(BuildContext)?, )); } } @@ -723,7 +725,7 @@ abstract class _$MenuActionCopyWith<$Res> implements $MenuActionCopyWith<$Res> { _MenuAction value, $Res Function(_MenuAction) then) = __$MenuActionCopyWithImpl<$Res>; @override - $Res call({String text, Icon icon, void Function()? action}); + $Res call({String text, Icon icon, void Function(BuildContext)? action}); } /// @nodoc @@ -754,7 +756,7 @@ class __$MenuActionCopyWithImpl<$Res> extends _$MenuActionCopyWithImpl<$Res> action: action == freezed ? _value.action : action // ignore: cast_nullable_to_non_nullable - as void Function()?, + as void Function(BuildContext)?, )); } } @@ -769,7 +771,7 @@ class _$_MenuAction implements _MenuAction { @override final Icon icon; @override - final void Function()? action; + final void Function(BuildContext)? action; @override String toString() { @@ -803,14 +805,14 @@ abstract class _MenuAction implements MenuAction { factory _MenuAction( {required String text, required Icon icon, - void Function()? action}) = _$_MenuAction; + void Function(BuildContext)? action}) = _$_MenuAction; @override String get text; @override Icon get icon; @override - void Function()? get action; + void Function(BuildContext)? get action; @override @JsonKey(ignore: true) _$MenuActionCopyWith<_MenuAction> get copyWith => diff --git a/lib/app/state.dart b/lib/app/state.dart index 9610f7f1..d672aa4c 100755 --- a/lib/app/state.dart +++ b/lib/app/state.dart @@ -116,15 +116,13 @@ class SubPageNotifier extends StateNotifier { } } -typedef BuildActions = List Function(BuildContext); - -final menuActionsProvider = Provider.autoDispose((ref) { +final menuActionsProvider = Provider.autoDispose>((ref) { switch (ref.watch(subPageProvider)) { case SubPage.authenticator: - return (context) => buildOathMenuActions(context, ref); + return buildOathMenuActions(ref); case SubPage.yubikey: // TODO: Handle this case. break; } - return (_) => []; + return []; }); diff --git a/lib/app/views/main_actions_dialog.dart b/lib/app/views/main_actions_dialog.dart index e84b7547..8ac8801e 100755 --- a/lib/app/views/main_actions_dialog.dart +++ b/lib/app/views/main_actions_dialog.dart @@ -14,7 +14,7 @@ class MainActionsDialog extends ConsumerWidget { final devices = ref.watch(attachedDevicesProvider).toList(); final currentNode = ref.watch(currentDeviceProvider); final data = ref.watch(currentDeviceDataProvider); - final actions = ref.watch(menuActionsProvider)(context); + final actions = ref.watch(menuActionsProvider); if (currentNode != null) { devices.removeWhere((e) => e.path == currentNode.path); @@ -56,7 +56,7 @@ class MainActionsDialog extends ConsumerWidget { title: Text(a.text), onTap: () { Navigator.of(context).pop(); - a.action?.call(); + a.action?.call(context); }, )), ], diff --git a/lib/oath/menu_actions.dart b/lib/oath/menu_actions.dart index 4c893aeb..be790b8b 100755 --- a/lib/oath/menu_actions.dart +++ b/lib/oath/menu_actions.dart @@ -8,8 +8,7 @@ import 'views/add_account_page.dart'; import 'views/password_dialog.dart'; import 'views/reset_dialog.dart'; -List buildOathMenuActions( - BuildContext context, AutoDisposeProviderRef ref) { +List buildOathMenuActions(AutoDisposeProviderRef ref) { final device = ref.watch(currentDeviceProvider); if (device != null) { final state = ref.watch(oathStateProvider(device.path)); @@ -19,7 +18,7 @@ List buildOathMenuActions( MenuAction( text: 'Add credential', icon: const Icon(Icons.add), - action: () { + action: (context) { Navigator.of(context).push( MaterialPageRoute( builder: (context) => OathAddAccountPage(device: device), @@ -31,7 +30,7 @@ List buildOathMenuActions( MenuAction( text: 'Manage password', icon: const Icon(Icons.password), - action: () { + action: (context) { showDialog( context: context, builder: (context) => ManagePasswordDialog(device), @@ -41,7 +40,7 @@ List buildOathMenuActions( MenuAction( text: 'Factory reset', icon: const Icon(Icons.delete_forever), - action: () { + action: (context) { showDialog( context: context, builder: (context) => ResetDialog(device),