2021-11-24 10:44:28 +03:00
|
|
|
import 'package:flutter/material.dart';
|
2022-02-10 13:20:21 +03:00
|
|
|
import 'package:flutter/services.dart';
|
2021-11-24 10:44:28 +03:00
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
|
2021-12-02 13:44:17 +03:00
|
|
|
import 'device_avatar.dart';
|
|
|
|
import 'main_actions_dialog.dart';
|
2021-11-24 10:44:28 +03:00
|
|
|
import 'main_drawer.dart';
|
|
|
|
import 'no_device_screen.dart';
|
|
|
|
import 'device_info_screen.dart';
|
|
|
|
import '../models.dart';
|
|
|
|
import '../state.dart';
|
|
|
|
import '../../oath/views/oath_screen.dart';
|
|
|
|
|
|
|
|
class MainPage extends ConsumerWidget {
|
|
|
|
const MainPage({Key? key}) : super(key: key);
|
|
|
|
|
2022-01-12 14:49:04 +03:00
|
|
|
Widget _buildSubPage(SubPage subPage, YubiKeyData? device) {
|
2021-12-02 13:44:17 +03:00
|
|
|
if (device == null) {
|
|
|
|
return const NoDeviceScreen();
|
|
|
|
}
|
2021-11-24 10:44:28 +03:00
|
|
|
// TODO: If page not supported by device, do something?
|
|
|
|
switch (subPage) {
|
|
|
|
case SubPage.authenticator:
|
|
|
|
return OathScreen(device);
|
|
|
|
case SubPage.yubikey:
|
|
|
|
return DeviceInfoScreen(device);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
2022-02-01 15:30:03 +03:00
|
|
|
final deviceNode = ref.watch(currentDeviceProvider);
|
2022-01-18 17:46:42 +03:00
|
|
|
final deviceData = ref.watch(currentDeviceDataProvider);
|
2021-11-24 10:44:28 +03:00
|
|
|
final subPage = ref.watch(subPageProvider);
|
|
|
|
|
2022-02-01 15:30:03 +03:00
|
|
|
Widget deviceWidget;
|
|
|
|
if (deviceNode != null) {
|
|
|
|
if (deviceData != null) {
|
|
|
|
deviceWidget = DeviceAvatar.yubiKeyData(
|
|
|
|
deviceData,
|
|
|
|
selected: true,
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
deviceWidget = DeviceAvatar.deviceNode(
|
|
|
|
deviceNode,
|
|
|
|
selected: true,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} else {
|
2022-02-09 15:05:32 +03:00
|
|
|
deviceWidget = const DeviceAvatar(
|
|
|
|
child: Icon(Icons.more_horiz),
|
2022-02-01 15:30:03 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-11-24 10:44:28 +03:00
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
2021-12-02 13:44:17 +03:00
|
|
|
/*
|
2021-12-02 22:29:40 +03:00
|
|
|
The following can be used to customize the appearence of the app bar,
|
|
|
|
should we wish to do so. More advanced changes may require using a
|
|
|
|
custom Widget instead.
|
|
|
|
|
2021-12-02 13:44:17 +03:00
|
|
|
backgroundColor: Colors.grey.shade900,
|
|
|
|
elevation: 0,
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
borderRadius: const BorderRadius.all(Radius.circular(40)),
|
|
|
|
side: BorderSide(
|
|
|
|
width: 8, color: Theme.of(context).scaffoldBackgroundColor),
|
|
|
|
),
|
|
|
|
*/
|
2022-02-10 13:20:21 +03:00
|
|
|
title: Focus(
|
|
|
|
canRequestFocus: false,
|
|
|
|
onKeyEvent: (node, event) {
|
|
|
|
if (event.logicalKey == LogicalKeyboardKey.arrowDown) {
|
|
|
|
node.focusInDirection(TraversalDirection.down);
|
|
|
|
return KeyEventResult.handled;
|
|
|
|
}
|
|
|
|
return KeyEventResult.ignored;
|
2021-12-02 13:44:17 +03:00
|
|
|
},
|
2022-02-10 13:20:21 +03:00
|
|
|
child: Builder(builder: (context) {
|
|
|
|
return TextField(
|
|
|
|
decoration: const InputDecoration(
|
|
|
|
hintText: 'Search...',
|
|
|
|
border: InputBorder.none,
|
|
|
|
),
|
|
|
|
onChanged: (value) {
|
|
|
|
ref.read(searchProvider.notifier).setFilter(value);
|
|
|
|
},
|
|
|
|
textInputAction: TextInputAction.next,
|
|
|
|
onSubmitted: (value) {
|
|
|
|
Focus.of(context).focusInDirection(TraversalDirection.down);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}),
|
2021-12-02 13:44:17 +03:00
|
|
|
),
|
2021-11-24 10:44:28 +03:00
|
|
|
actions: [
|
2022-02-01 18:36:19 +03:00
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(right: 8.0),
|
|
|
|
child: IconButton(
|
|
|
|
icon: OverflowBox(
|
|
|
|
maxHeight: 44,
|
|
|
|
maxWidth: 44,
|
|
|
|
child: deviceWidget,
|
|
|
|
),
|
|
|
|
onPressed: () {
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (context) => const MainActionsDialog(),
|
|
|
|
);
|
|
|
|
},
|
2021-12-07 14:53:05 +03:00
|
|
|
),
|
2021-12-07 16:22:28 +03:00
|
|
|
),
|
2021-11-24 10:44:28 +03:00
|
|
|
],
|
|
|
|
),
|
|
|
|
drawer: const MainPageDrawer(),
|
2022-01-18 17:46:42 +03:00
|
|
|
body: _buildSubPage(subPage, deviceData),
|
2021-11-24 10:44:28 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|