mirror of
https://github.com/Yubico/yubioath-flutter.git
synced 2024-11-26 22:03:55 +03:00
AppPage improvements.
- Make AppPage content scrollable. - Add optional FAB (with extra padding for FAB). - Add bottomMenu.
This commit is contained in:
parent
2f13399b09
commit
40d616c8bd
@ -1,4 +1,8 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import 'models.dart';
|
||||
import 'state.dart';
|
||||
|
||||
ScaffoldFeatureController showMessage(
|
||||
BuildContext context,
|
||||
@ -14,3 +18,43 @@ ScaffoldFeatureController showMessage(
|
||||
width: narrow ? null : 400,
|
||||
));
|
||||
}
|
||||
|
||||
Future<void> showBottomMenu(
|
||||
BuildContext context, List<MenuAction> actions) async {
|
||||
await showModalBottomSheet(
|
||||
context: context,
|
||||
constraints: MediaQuery.of(context).size.width > 540
|
||||
? const BoxConstraints(maxWidth: 380)
|
||||
: null,
|
||||
builder: (context) => _BottomMenu(actions),
|
||||
);
|
||||
}
|
||||
|
||||
class _BottomMenu extends ConsumerWidget {
|
||||
final List<MenuAction> actions;
|
||||
const _BottomMenu(this.actions);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
// If current device changes, we need to pop back to the main Page.
|
||||
ref.listen<DeviceNode?>(currentDeviceProvider, (previous, next) {
|
||||
Navigator.of(context).pop();
|
||||
});
|
||||
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: actions
|
||||
.map((a) => ListTile(
|
||||
leading: a.icon,
|
||||
title: Text(a.text),
|
||||
onTap: a.action == null
|
||||
? null
|
||||
: () {
|
||||
Navigator.pop(context);
|
||||
a.action?.call(context);
|
||||
},
|
||||
))
|
||||
.toList(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -93,6 +93,9 @@ class DevicePath {
|
||||
int get hashCode => Object.hashAll(segments);
|
||||
|
||||
String get key => segments.join('/');
|
||||
|
||||
@override
|
||||
String toString() => key;
|
||||
}
|
||||
|
||||
@freezed
|
||||
|
@ -9,13 +9,13 @@ class AppPage extends ConsumerWidget {
|
||||
final Widget? title;
|
||||
final Widget child;
|
||||
final Widget? floatingActionButton;
|
||||
final void Function()? onBack;
|
||||
final bool centered;
|
||||
AppPage(
|
||||
{Key? key,
|
||||
this.title,
|
||||
required this.child,
|
||||
this.onBack,
|
||||
this.floatingActionButton})
|
||||
this.floatingActionButton,
|
||||
this.centered = false})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
@ -45,21 +45,24 @@ class AppPage extends ConsumerWidget {
|
||||
},
|
||||
);
|
||||
|
||||
Widget _buildScrollView() => SingleChildScrollView(
|
||||
// Make sure FAB doesn't block content
|
||||
padding: floatingActionButton != null
|
||||
? const EdgeInsets.only(bottom: 72)
|
||||
: null,
|
||||
child: child,
|
||||
);
|
||||
|
||||
Scaffold _buildScaffold(BuildContext context, WidgetRef ref, bool hasDrawer) {
|
||||
return Scaffold(
|
||||
key: _scaffoldKey,
|
||||
appBar: AppBar(
|
||||
leading: onBack != null
|
||||
? BackButton(
|
||||
onPressed: onBack,
|
||||
)
|
||||
: null,
|
||||
title: title,
|
||||
centerTitle: true,
|
||||
actions: const [DeviceButton()],
|
||||
),
|
||||
drawer: hasDrawer ? const MainPageDrawer() : null,
|
||||
body: child,
|
||||
body: centered ? Center(child: _buildScrollView()) : _buildScrollView(),
|
||||
floatingActionButton: floatingActionButton,
|
||||
);
|
||||
}
|
||||
|
@ -10,14 +10,9 @@ class DeviceInfoScreen extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AppPage(
|
||||
child: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: const [
|
||||
Text('This page intentionally left blank (for now)'),
|
||||
],
|
||||
),
|
||||
),
|
||||
title: const Text('Coming soon!'),
|
||||
centered: true,
|
||||
child: const Text('This page intentionally left blank (for now)'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ class MainPage extends ConsumerWidget {
|
||||
|
||||
switch (app) {
|
||||
case Application.oath:
|
||||
return OathScreen(deviceData);
|
||||
return OathScreen(deviceData.node.path);
|
||||
case Application.management:
|
||||
return ManagementScreen(deviceData);
|
||||
case Application.fido:
|
||||
|
@ -58,7 +58,7 @@ class NoDeviceScreen extends ConsumerWidget {
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
return AppPage(
|
||||
child: Center(
|
||||
centered: true,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: node?.map(usbYubiKey: (node) {
|
||||
@ -74,7 +74,6 @@ class NoDeviceScreen extends ConsumerWidget {
|
||||
Text('Insert your YubiKey'),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user