2021-11-24 10:44:28 +03:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
|
2022-04-05 12:46:22 +03:00
|
|
|
import 'message_page.dart';
|
2021-11-24 10:44:28 +03:00
|
|
|
import 'no_device_screen.dart';
|
|
|
|
import '../models.dart';
|
|
|
|
import '../state.dart';
|
2022-03-15 19:16:14 +03:00
|
|
|
import '../../fido/views/fido_screen.dart';
|
2021-11-24 10:44:28 +03:00
|
|
|
import '../../oath/views/oath_screen.dart';
|
2022-03-04 15:42:10 +03:00
|
|
|
import '../../management/views/management_screen.dart';
|
2021-11-24 10:44:28 +03:00
|
|
|
|
|
|
|
class MainPage extends ConsumerWidget {
|
2022-05-12 10:56:55 +03:00
|
|
|
const MainPage({super.key});
|
2021-11-24 10:44:28 +03:00
|
|
|
|
2022-03-25 18:24:15 +03:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
2022-03-25 10:59:02 +03:00
|
|
|
ref.listen<Function(BuildContext)?>(
|
2022-04-28 16:23:04 +03:00
|
|
|
contextConsumer,
|
2022-03-25 10:59:02 +03:00
|
|
|
(previous, next) {
|
|
|
|
next?.call(context);
|
|
|
|
},
|
|
|
|
);
|
2022-03-25 18:24:15 +03:00
|
|
|
final deviceData = ref.watch(currentDeviceDataProvider);
|
|
|
|
if (deviceData == null) {
|
|
|
|
final node = ref.watch(currentDeviceProvider);
|
|
|
|
return NoDeviceScreen(node);
|
|
|
|
}
|
|
|
|
final app = ref.watch(currentAppProvider);
|
2022-03-16 15:14:20 +03:00
|
|
|
if (app.getAvailability(deviceData) != Availability.enabled) {
|
2022-04-05 12:46:22 +03:00
|
|
|
return const MessagePage(
|
|
|
|
header: 'Application disabled',
|
|
|
|
message: 'Enable the application on your YubiKey to access',
|
2022-03-07 11:57:29 +03:00
|
|
|
);
|
|
|
|
}
|
2022-03-14 12:57:00 +03:00
|
|
|
|
2022-03-16 15:14:20 +03:00
|
|
|
switch (app) {
|
2022-03-14 13:48:39 +03:00
|
|
|
case Application.oath:
|
2022-04-03 12:03:03 +03:00
|
|
|
return OathScreen(deviceData.node.path);
|
2022-03-14 13:48:39 +03:00
|
|
|
case Application.management:
|
2022-03-16 15:14:20 +03:00
|
|
|
return ManagementScreen(deviceData);
|
2022-03-15 19:16:14 +03:00
|
|
|
case Application.fido:
|
2022-03-16 15:14:20 +03:00
|
|
|
return FidoScreen(deviceData);
|
2022-02-24 17:19:57 +03:00
|
|
|
default:
|
2022-04-05 13:41:35 +03:00
|
|
|
return const MessagePage(
|
|
|
|
header: 'Not implemented',
|
|
|
|
message: 'This section has not yet been implemented',
|
|
|
|
);
|
2021-11-24 10:44:28 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|