OpenMediacenterMobileFlutter/lib/DrawerPage.dart

144 lines
3.5 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
import 'package:openmediacentermobile/navigation/settings_screen.dart';
import 'db/database.dart';
import 'navigation/actor_screen.dart';
import 'navigation/categorie_screen.dart';
import 'navigation/shufflescreen.dart';
import 'navigation/video_feed.dart';
import 'api/token.dart';
import 'login/logincontext.dart';
class DrawerPage extends StatefulWidget {
const DrawerPage({Key? key, required this.title}) : super(key: key);
final String title;
@override
_DrawerPageState createState() => _DrawerPageState();
}
enum Section { HOME, SHUFFLE, SETTING, CATEGORIE, ACTOR }
class _DrawerPageState extends State<DrawerPage> {
Section _sec = Section.HOME;
@override
Widget build(BuildContext context) {
Widget body;
String title;
switch (_sec) {
case Section.HOME:
body = const VideoFeed();
title = widget.title;
break;
case Section.SHUFFLE:
body = const ShuffleScreen();
title = "Shuffle";
break;
case Section.SETTING:
body = SettingsScreen();
title = "Settings";
break;
case Section.CATEGORIE:
body = CategorieScreen();
title = "Categories";
break;
case Section.ACTOR:
body = ActorScreen();
title = "Actors";
break;
}
return DrawerContext((newPage) {
setState(() {
_sec = newPage;
});
}, child: body);
}
}
class MyDrawer extends StatelessWidget {
const MyDrawer({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
final ctx = DrawerContext.of(context);
return Drawer(
child: ListView(children: [
ListTile(
title: const Text('Home'),
leading: const Icon(Icons.home),
onTap: () {
ctx.onChangePage(Section.HOME);
Navigator.pop(context);
},
),
ListTile(
title: const Text('Shuffle'),
leading: const Icon(Icons.update),
onTap: () {
ctx.onChangePage(Section.SHUFFLE);
Navigator.pop(context);
},
),
ListTile(
title: const Text('Categories'),
leading: const Icon(Icons.category),
onTap: () {
ctx.onChangePage(Section.CATEGORIE);
Navigator.pop(context);
},
),
ListTile(
title: const Text('Actors'),
leading: const Icon(Icons.people),
onTap: () {
ctx.onChangePage(Section.ACTOR);
Navigator.pop(context);
},
),
ListTile(
title: const Text('Settings'),
leading: const Icon(Icons.settings),
onTap: () {
ctx.onChangePage(Section.SETTING);
Navigator.pop(context);
},
),
]),
);
}
}
class DrawerContext extends InheritedWidget {
const DrawerContext(this.onChangePage, {Key? key, required Widget child})
: super(key: key, child: child);
final void Function(Section) onChangePage;
static DrawerContext of(BuildContext context) {
final DrawerContext? result =
context.dependOnInheritedWidgetOfExactType<DrawerContext>();
assert(result != null, 'No DrawerContext found in context');
return result!;
}
@override
bool updateShouldNotify(covariant InheritedWidget oldWidget) {
return false;
}
// @override
// bool updateShouldNotify(LoginContext old) {
// return loggedIn != old.loggedIn;
// }
}