yubioath-flutter/lib/app/views/app_page.dart
Dain Nilsson 40d616c8bd
AppPage improvements.
- Make AppPage content scrollable.
- Add optional FAB (with extra padding for FAB).
- Add bottomMenu.
2022-04-03 11:03:03 +02:00

70 lines
2.0 KiB
Dart
Executable File

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'device_button.dart';
import 'main_drawer.dart';
class AppPage extends ConsumerWidget {
final Key _scaffoldKey = GlobalKey();
final Widget? title;
final Widget child;
final Widget? floatingActionButton;
final bool centered;
AppPage(
{Key? key,
this.title,
required this.child,
this.floatingActionButton,
this.centered = false})
: super(key: key);
@override
Widget build(BuildContext context, WidgetRef ref) => LayoutBuilder(
builder: (context, constraints) {
if (constraints.maxWidth < 540) {
// Single column layout
return _buildScaffold(context, ref, true);
} else {
// Two-column layout
return Scaffold(
body: Row(
children: [
const SizedBox(
width: 240,
child: ListTileTheme(
style: ListTileStyle.drawer,
child: MainPageDrawer(shouldPop: false)),
),
Expanded(
child: _buildScaffold(context, ref, false),
),
],
),
);
}
},
);
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(
title: title,
centerTitle: true,
actions: const [DeviceButton()],
),
drawer: hasDrawer ? const MainPageDrawer() : null,
body: centered ? Center(child: _buildScrollView()) : _buildScrollView(),
floatingActionButton: floatingActionButton,
);
}
}