Add placeholders for additional sub pages.

This commit is contained in:
Dain Nilsson 2022-02-24 15:19:57 +01:00
parent a92dd12818
commit e1f5879f42
No known key found for this signature in database
GPG Key ID: F04367096FBA95E8
5 changed files with 35 additions and 43 deletions

View File

@ -4,7 +4,7 @@ import '../../management/models.dart';
part 'models.freezed.dart';
enum SubPage { authenticator, yubikey }
enum SubPage { oath, fido, otp, piv, management }
@freezed
class YubiKeyData with _$YubiKeyData {

View File

@ -107,7 +107,7 @@ class CurrentDeviceNotifier extends StateNotifier<DeviceNode?> {
}
final subPageProvider = StateNotifierProvider<SubPageNotifier, SubPage>(
(ref) => SubPageNotifier(SubPage.authenticator));
(ref) => SubPageNotifier(SubPage.oath));
class SubPageNotifier extends StateNotifier<SubPage> {
SubPageNotifier(SubPage state) : super(state);
@ -119,13 +119,12 @@ class SubPageNotifier extends StateNotifier<SubPage> {
final menuActionsProvider = Provider.autoDispose<List<MenuAction>>((ref) {
switch (ref.watch(subPageProvider)) {
case SubPage.authenticator:
case SubPage.oath:
return buildOathMenuActions(ref);
case SubPage.yubikey:
// TODO: Handle this case.
break;
// TODO: Handle other cases.
default:
return [];
}
return [];
});
abstract class QrScanner {

View File

@ -11,10 +11,8 @@ class DeviceInfoScreen extends StatelessWidget {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('YubiKey: ${device.name}'),
Text('Serial: ${device.info.serial}'),
Text('Version: ${device.info.version}'),
children: const [
Text('This page intentionally left blank (for now)'),
],
),
);

View File

@ -9,10 +9,16 @@ import '../state.dart';
extension on SubPage {
String get displayName {
switch (this) {
case SubPage.authenticator:
case SubPage.oath:
return 'Authenticator';
case SubPage.yubikey:
return 'YubiKey';
case SubPage.fido:
return 'WebAuthn';
case SubPage.otp:
return 'One-Time Passwords';
case SubPage.piv:
return 'Certificates';
case SubPage.management:
return 'Toggle applications';
}
}
}
@ -22,10 +28,16 @@ class MainPageDrawer extends ConsumerWidget {
IconData _iconFor(SubPage page) {
switch (page) {
case SubPage.authenticator:
case SubPage.oath:
return Icons.supervisor_account;
default:
return Icons.miscellaneous_services;
case SubPage.fido:
return Icons.security;
case SubPage.otp:
return Icons.password;
case SubPage.piv:
return Icons.approval;
case SubPage.management:
return Icons.construction;
}
}
@ -33,6 +45,8 @@ class MainPageDrawer extends ConsumerWidget {
Widget build(BuildContext context, WidgetRef ref) {
final currentSubPage = ref.watch(subPageProvider);
final mainPages = [SubPage.oath, SubPage.fido, SubPage.otp, SubPage.piv];
return Drawer(
child: ListView(
primary: false, //Prevents conflict with the MainPage scroll view.
@ -44,7 +58,7 @@ class MainPageDrawer extends ConsumerWidget {
style: Theme.of(context).textTheme.headline6,
),
),
...[SubPage.authenticator].map((page) => DrawerItem(
...mainPages.map((page) => DrawerItem(
titleText: page.displayName,
icon: Icon(_iconFor(page)),
selected: page == currentSubPage,
@ -55,28 +69,6 @@ class MainPageDrawer extends ConsumerWidget {
}
: null,
)),
// PLACEHOLDERS
DrawerItem(
titleText: 'WebAuthn',
icon: const Icon(Icons.security),
onTap: () {
Navigator.of(context).pop();
},
),
DrawerItem(
titleText: 'One-Time Passwords',
icon: const Icon(Icons.password),
onTap: () {
Navigator.of(context).pop();
},
),
DrawerItem(
titleText: 'Certificates',
icon: const Icon(Icons.approval),
onTap: () {
Navigator.of(context).pop();
},
),
const Divider(),
Padding(
padding: const EdgeInsets.all(16.0),
@ -85,10 +77,13 @@ class MainPageDrawer extends ConsumerWidget {
style: Theme.of(context).textTheme.bodyText2,
),
),
// PLACEHOLDER
DrawerItem(
titleText: 'Toggle applications',
icon: const Icon(Icons.construction),
icon: Icon(_iconFor(SubPage.management)),
selected: SubPage.management == currentSubPage,
onTap: () {
ref.read(subPageProvider.notifier).setSubPage(SubPage.management);
Navigator.of(context).pop();
},
),

View File

@ -20,9 +20,9 @@ class MainPage extends ConsumerWidget {
}
// TODO: If page not supported by device, do something?
switch (subPage) {
case SubPage.authenticator:
case SubPage.oath:
return OathScreen(device);
case SubPage.yubikey:
default:
return DeviceInfoScreen(device);
}
}