mirror of
https://github.com/Yubico/yubioath-flutter.git
synced 2024-12-22 17:51:29 +03:00
Pass in BuildContext to MenuItem.action.
Instead of when constructing the MenuItem itself.
This commit is contained in:
parent
af652b3609
commit
939f590b09
@ -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
|
||||
|
@ -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<MenuAction> 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 =>
|
||||
|
@ -116,15 +116,13 @@ class SubPageNotifier extends StateNotifier<SubPage> {
|
||||
}
|
||||
}
|
||||
|
||||
typedef BuildActions = List<MenuAction> Function(BuildContext);
|
||||
|
||||
final menuActionsProvider = Provider.autoDispose<BuildActions>((ref) {
|
||||
final menuActionsProvider = Provider.autoDispose<List<MenuAction>>((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 [];
|
||||
});
|
||||
|
@ -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);
|
||||
},
|
||||
)),
|
||||
],
|
||||
|
@ -8,8 +8,7 @@ import 'views/add_account_page.dart';
|
||||
import 'views/password_dialog.dart';
|
||||
import 'views/reset_dialog.dart';
|
||||
|
||||
List<MenuAction> buildOathMenuActions(
|
||||
BuildContext context, AutoDisposeProviderRef ref) {
|
||||
List<MenuAction> buildOathMenuActions(AutoDisposeProviderRef ref) {
|
||||
final device = ref.watch(currentDeviceProvider);
|
||||
if (device != null) {
|
||||
final state = ref.watch(oathStateProvider(device.path));
|
||||
@ -19,7 +18,7 @@ List<MenuAction> 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<MenuAction> 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<MenuAction> buildOathMenuActions(
|
||||
MenuAction(
|
||||
text: 'Factory reset',
|
||||
icon: const Icon(Icons.delete_forever),
|
||||
action: () {
|
||||
action: (context) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => ResetDialog(device),
|
||||
|
Loading…
Reference in New Issue
Block a user