mirror of
https://github.com/Yubico/yubioath-flutter.git
synced 2024-12-23 02:01:36 +03:00
Break up large files into smaller.
This commit is contained in:
parent
cc1426caf1
commit
2cd9ff2283
@ -1,101 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import 'no_device_screen.dart';
|
||||
import 'device_info_screen.dart';
|
||||
import 'models.dart';
|
||||
import 'state.dart';
|
||||
|
||||
import '../../about_page.dart';
|
||||
import '../oath/views/oath_screen.dart';
|
||||
|
||||
class MainPage extends ConsumerWidget {
|
||||
const MainPage({Key? key}) : super(key: key);
|
||||
|
||||
Widget _buildSubPage(SubPage subPage, DeviceNode device) {
|
||||
// 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) {
|
||||
final currentDevice = ref.watch(currentDeviceProvider);
|
||||
final subPage = ref.watch(subPageProvider);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Yubico Authenticator'),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.info),
|
||||
onPressed: () {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(builder: (context) => const AboutPage()),
|
||||
);
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
drawer: MainPageDrawer(
|
||||
subPage,
|
||||
onSelect: (page) {
|
||||
ref.read(subPageProvider.notifier).setSubPage(page);
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
body: currentDevice == null
|
||||
? const NoDeviceScreen()
|
||||
: _buildSubPage(subPage, currentDevice),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
extension on SubPage {
|
||||
String get displayName {
|
||||
switch (this) {
|
||||
case SubPage.authenticator:
|
||||
return 'Authenticator';
|
||||
case SubPage.yubikey:
|
||||
return 'YubiKey';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class MainPageDrawer extends StatelessWidget {
|
||||
final SubPage currentSubPage;
|
||||
final void Function(SubPage) onSelect;
|
||||
const MainPageDrawer(this.currentSubPage, {required this.onSelect, Key? key})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Drawer(
|
||||
child: ListView(
|
||||
children: [
|
||||
const DrawerHeader(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.blue,
|
||||
),
|
||||
child: Text('Hello'),
|
||||
),
|
||||
...SubPage.values.map((value) => ListTile(
|
||||
title: Text(
|
||||
value.displayName,
|
||||
style: Theme.of(context).textTheme.headline6,
|
||||
),
|
||||
tileColor: value == currentSubPage ? Colors.blueGrey : null,
|
||||
enabled: value != currentSubPage,
|
||||
onTap: () {
|
||||
onSelect(value);
|
||||
},
|
||||
)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'models.dart';
|
||||
import '../models.dart';
|
||||
|
||||
class DeviceInfoScreen extends StatelessWidget {
|
||||
final DeviceNode device;
|
50
lib/app/views/main_drawer.dart
Executable file
50
lib/app/views/main_drawer.dart
Executable file
@ -0,0 +1,50 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../models.dart';
|
||||
import '../state.dart';
|
||||
|
||||
extension on SubPage {
|
||||
String get displayName {
|
||||
switch (this) {
|
||||
case SubPage.authenticator:
|
||||
return 'Authenticator';
|
||||
case SubPage.yubikey:
|
||||
return 'YubiKey';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class MainPageDrawer extends ConsumerWidget {
|
||||
const MainPageDrawer({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final currentSubPage = ref.watch(subPageProvider);
|
||||
|
||||
return Drawer(
|
||||
child: ListView(
|
||||
children: [
|
||||
const DrawerHeader(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.blue,
|
||||
),
|
||||
child: Text('Hello'),
|
||||
),
|
||||
...SubPage.values.map((value) => ListTile(
|
||||
title: Text(
|
||||
value.displayName,
|
||||
style: Theme.of(context).textTheme.headline6,
|
||||
),
|
||||
tileColor: value == currentSubPage ? Colors.blueGrey : null,
|
||||
enabled: value != currentSubPage,
|
||||
onTap: () {
|
||||
ref.read(subPageProvider.notifier).setSubPage(value);
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
50
lib/app/views/main_page.dart
Executable file
50
lib/app/views/main_page.dart
Executable file
@ -0,0 +1,50 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import 'main_drawer.dart';
|
||||
import 'no_device_screen.dart';
|
||||
import 'device_info_screen.dart';
|
||||
import '../models.dart';
|
||||
import '../state.dart';
|
||||
import '../../about_page.dart';
|
||||
import '../../oath/views/oath_screen.dart';
|
||||
|
||||
class MainPage extends ConsumerWidget {
|
||||
const MainPage({Key? key}) : super(key: key);
|
||||
|
||||
Widget _buildSubPage(SubPage subPage, DeviceNode device) {
|
||||
// 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) {
|
||||
final currentDevice = ref.watch(currentDeviceProvider);
|
||||
final subPage = ref.watch(subPageProvider);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Yubico Authenticator'),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.info),
|
||||
onPressed: () {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(builder: (context) => const AboutPage()),
|
||||
);
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
drawer: const MainPageDrawer(),
|
||||
body: currentDevice == null
|
||||
? const NoDeviceScreen()
|
||||
: _buildSubPage(subPage, currentDevice),
|
||||
);
|
||||
}
|
||||
}
|
@ -7,10 +7,10 @@ import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
|
||||
import 'app.dart';
|
||||
import 'app/views/main_page.dart';
|
||||
import 'core/rpc.dart';
|
||||
import 'core/state.dart';
|
||||
|
||||
import 'app/main_page.dart';
|
||||
import 'error_page.dart';
|
||||
|
||||
final log = Logger('main');
|
||||
|
Loading…
Reference in New Issue
Block a user