yubioath-flutter/lib/oath/menu_actions.dart

55 lines
1.5 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));
if (state != null) {
return [
if (!state.locked)
MenuAction(
text: 'Add credential',
icon: const Icon(Icons.add),
action: (context) {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => OathAddAccountPage(device: device),
),
);
},
),
2021-12-08 13:20:04 +03:00
if (!state.locked)
MenuAction(
text: 'Manage password',
icon: const Icon(Icons.password),
action: (context) {
2021-12-08 13:20:04 +03:00
showDialog(
context: context,
builder: (context) => ManagePasswordDialog(device),
);
},
),
MenuAction(
text: 'Factory reset',
icon: const Icon(Icons.delete_forever),
action: (context) {
2022-01-21 13:30:14 +03:00
showDialog(
context: context,
builder: (context) => ResetDialog(device),
);
},
),
];
}
}
return [];
}