yubioath-flutter/lib/app/views/main_page.dart

119 lines
3.5 KiB
Dart
Raw Normal View History

2021-11-24 10:44:28 +03:00
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
2021-11-24 10:44:28 +03:00
import 'package:flutter_riverpod/flutter_riverpod.dart';
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) {
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 {
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 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.
backgroundColor: Colors.grey.shade900,
elevation: 0,
shape: RoundedRectangleBorder(
borderRadius: const BorderRadius.all(Radius.circular(40)),
side: BorderSide(
width: 8, color: Theme.of(context).scaffoldBackgroundColor),
),
*/
title: Focus(
canRequestFocus: false,
onKeyEvent: (node, event) {
if (event.logicalKey == LogicalKeyboardKey.arrowDown) {
node.focusInDirection(TraversalDirection.down);
return KeyEventResult.handled;
}
return KeyEventResult.ignored;
},
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-11-24 10:44:28 +03:00
actions: [
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
);
}
}