OpenMediacenterMobileFlutter/lib/DrawerPage.dart
lukas-heiligenbrunner c732ab31df fix linting
add routename in privider
2022-08-29 17:20:35 +02:00

143 lines
3.4 KiB
Dart

import 'package:flutter/material.dart';
import 'package:openmediacentermobile/navigation/settings_screen.dart';
import 'navigation/actor_screen.dart';
import 'navigation/categorie_screen.dart';
import 'navigation/shufflescreen.dart';
import 'navigation/video_feed.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(
child: body,
onChangePage: (newPage) {
setState(() {
_sec = newPage;
});
},
routeName: title,
);
}
}
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({
Key? key,
required Widget child,
required this.onChangePage,
required this.routeName,
}) : super(key: key, child: child);
final void Function(Section) onChangePage;
final String routeName;
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;
}
}