add drawer in home page
This commit is contained in:
@@ -3,6 +3,7 @@ import 'package:logging/logging.dart';
|
||||
import 'package:sheetless/login_page.dart';
|
||||
import 'package:sheetless/sheet_viewer_page.dart';
|
||||
import 'package:sheetless/storage_helper.dart';
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
|
||||
import 'api.dart';
|
||||
import 'sheet.dart';
|
||||
@@ -21,10 +22,22 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
Future<bool> apiLoggedIn = Future.value(false);
|
||||
final StorageHelper _storageHelper = StorageHelper();
|
||||
final log = Logger("MyHomePage");
|
||||
String? appName;
|
||||
String? appVersion;
|
||||
bool shuffling = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadAppInfo();
|
||||
}
|
||||
|
||||
Future<void> _loadAppInfo() async {
|
||||
final info = await PackageInfo.fromPlatform();
|
||||
setState(() {
|
||||
appName = info.appName;
|
||||
appVersion = info.version;
|
||||
});
|
||||
}
|
||||
|
||||
Future<List<Sheet>> acquireSheets() async {
|
||||
@@ -72,19 +85,68 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
).pushReplacement(MaterialPageRoute(builder: (_) => LoginPage()));
|
||||
}
|
||||
|
||||
Drawer _buildDrawer() {
|
||||
return Drawer(
|
||||
child: SafeArea(
|
||||
child: Padding(
|
||||
padding: EdgeInsetsGeometry.directional(start: 10, end: 10, top: 30),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
// Drawer Actions
|
||||
Column(
|
||||
children: [
|
||||
ListTile(
|
||||
leading: Icon(
|
||||
Icons.shuffle,
|
||||
color: shuffling ? Colors.blue : null,
|
||||
),
|
||||
title: const Text('Shuffle'),
|
||||
trailing: Switch(
|
||||
value: shuffling,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
shuffling = value;
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.sync),
|
||||
title: const Text('Sync Mode'),
|
||||
onTap: () {
|
||||
// TODO
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.logout),
|
||||
title: const Text('Logout'),
|
||||
onTap: _logOut,
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
// App Info at bottom
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Text(
|
||||
'$appName v$appVersion',
|
||||
style: const TextStyle(color: Colors.grey),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text("Sheetless"),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.logout),
|
||||
tooltip: 'Logout',
|
||||
onPressed: _logOut,
|
||||
),
|
||||
],
|
||||
),
|
||||
// Icon for drawer appears automatically
|
||||
appBar: AppBar(title: const Text("Sheetless")),
|
||||
endDrawer: _buildDrawer(),
|
||||
body: FutureBuilder(
|
||||
future: acquireSheets(),
|
||||
builder: (BuildContext context, AsyncSnapshot<List<Sheet>> snapshot) {
|
||||
|
||||
Reference in New Issue
Block a user