yubioath-flutter/lib/oath/menu_actions.dart

55 lines
1.9 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../app/models.dart';
import '../app/state.dart';
import 'state.dart';
import 'views/add_account_page.dart';
2021-12-08 13:20:04 +03:00
import 'views/password_dialog.dart';
2022-01-21 13:30:14 +03:00
import 'views/reset_dialog.dart';
List<MenuAction> buildOathMenuActions(AutoDisposeProviderRef ref) {
final device = ref.watch(currentDeviceProvider);
if (device != null) {
final state = ref.watch(oathStateProvider(device.path));
2022-03-09 19:47:50 +03:00
return state.whenOrNull(
success: (oathState) => [
if (!oathState.locked) ...[
MenuAction(
text: 'Add credential',
icon: const Icon(Icons.add),
action: (context) {
2022-03-15 20:04:26 +03:00
showDialog(
context: context,
builder: (context) =>
OathAddAccountPage(device: device),
2022-03-09 19:47:50 +03:00
);
},
),
MenuAction(
text: 'Manage password',
icon: const Icon(Icons.password),
action: (context) {
showDialog(
context: context,
builder: (context) => ManagePasswordDialog(device),
);
},
),
],
MenuAction(
text: 'Factory reset',
icon: const Icon(Icons.delete_forever),
action: (context) {
showDialog(
context: context,
builder: (context) => ResetDialog(device),
);
},
),
]) ??
[];
}
return [];
}