2022-04-15 19:57:15 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2022-08-28 20:51:12 +00:00
|
|
|
import 'package:openmediacentermobile/navigation/settings_screen.dart';
|
|
|
|
import 'navigation/actor_screen.dart';
|
2022-08-28 16:48:53 +00:00
|
|
|
import 'navigation/categorie_screen.dart';
|
|
|
|
import 'navigation/shufflescreen.dart';
|
|
|
|
import 'navigation/video_feed.dart';
|
2022-04-15 19:57:15 +00:00
|
|
|
|
|
|
|
class DrawerPage extends StatefulWidget {
|
|
|
|
const DrawerPage({Key? key, required this.title}) : super(key: key);
|
|
|
|
|
|
|
|
final String title;
|
|
|
|
|
|
|
|
@override
|
|
|
|
_DrawerPageState createState() => _DrawerPageState();
|
|
|
|
}
|
|
|
|
|
2022-08-29 15:16:51 +00:00
|
|
|
enum Section { HOME, SHUFFLE, SETTING, CATEGORIE, ACTOR }
|
2022-04-15 19:57:15 +00:00
|
|
|
|
|
|
|
class _DrawerPageState extends State<DrawerPage> {
|
2022-08-25 17:48:09 +00:00
|
|
|
Section _sec = Section.HOME;
|
2022-04-15 19:57:15 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
Widget body;
|
|
|
|
String title;
|
|
|
|
|
2022-08-25 17:48:09 +00:00
|
|
|
switch (_sec) {
|
2022-04-15 19:57:15 +00:00
|
|
|
case Section.HOME:
|
|
|
|
body = const VideoFeed();
|
|
|
|
title = widget.title;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Section.SHUFFLE:
|
|
|
|
body = const ShuffleScreen();
|
|
|
|
title = "Shuffle";
|
|
|
|
break;
|
|
|
|
|
2022-08-29 15:16:51 +00:00
|
|
|
case Section.SETTING:
|
2022-08-28 20:51:12 +00:00
|
|
|
body = SettingsScreen();
|
2022-04-15 19:57:15 +00:00
|
|
|
title = "Settings";
|
|
|
|
break;
|
2022-08-28 16:48:53 +00:00
|
|
|
|
|
|
|
case Section.CATEGORIE:
|
|
|
|
body = CategorieScreen();
|
|
|
|
title = "Categories";
|
|
|
|
break;
|
2022-08-28 20:51:12 +00:00
|
|
|
|
|
|
|
case Section.ACTOR:
|
|
|
|
body = ActorScreen();
|
|
|
|
title = "Actors";
|
|
|
|
break;
|
2022-04-15 19:57:15 +00:00
|
|
|
}
|
|
|
|
|
2022-08-29 15:20:35 +00:00
|
|
|
return DrawerContext(
|
|
|
|
child: body,
|
|
|
|
onChangePage: (newPage) {
|
|
|
|
setState(() {
|
|
|
|
_sec = newPage;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
routeName: title,
|
|
|
|
);
|
2022-08-29 15:16:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
]),
|
2022-04-15 19:57:15 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2022-08-29 15:16:51 +00:00
|
|
|
|
|
|
|
class DrawerContext extends InheritedWidget {
|
2022-08-29 15:20:35 +00:00
|
|
|
const DrawerContext({
|
|
|
|
Key? key,
|
|
|
|
required Widget child,
|
|
|
|
required this.onChangePage,
|
|
|
|
required this.routeName,
|
|
|
|
}) : super(key: key, child: child);
|
2022-08-29 15:16:51 +00:00
|
|
|
|
|
|
|
final void Function(Section) onChangePage;
|
2022-08-29 15:20:35 +00:00
|
|
|
final String routeName;
|
2022-08-29 15:16:51 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|