outsource drawer context in seperate files
This commit is contained in:
parent
405d7e420e
commit
02bf3fb341
@ -1,142 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -4,7 +4,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:openmediacentermobile/log/log.dart';
|
import 'package:openmediacentermobile/log/log.dart';
|
||||||
import 'package:openmediacentermobile/login/login_screen.dart';
|
import 'package:openmediacentermobile/login/login_screen.dart';
|
||||||
|
|
||||||
import 'DrawerPage.dart';
|
import 'drawer/drawer_page.dart';
|
||||||
import 'login/logincontext.dart';
|
import 'login/logincontext.dart';
|
||||||
|
|
||||||
class AppScrollBehavior extends MaterialScrollBehavior {
|
class AppScrollBehavior extends MaterialScrollBehavior {
|
||||||
|
27
lib/drawer/drawer_context.dart
Normal file
27
lib/drawer/drawer_context.dart
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import 'drawer_page.dart';
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
65
lib/drawer/drawer_page.dart
Normal file
65
lib/drawer/drawer_page.dart
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
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';
|
||||||
|
import 'drawer_context.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,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
58
lib/drawer/my_drawer.dart
Normal file
58
lib/drawer/my_drawer.dart
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import 'drawer_context.dart';
|
||||||
|
import 'drawer_page.dart';
|
||||||
|
|
||||||
|
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);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -6,7 +6,7 @@ import 'app.dart';
|
|||||||
import 'db/database.dart';
|
import 'db/database.dart';
|
||||||
import 'log/log.dart';
|
import 'log/log.dart';
|
||||||
import 'login/logincontext.dart';
|
import 'login/logincontext.dart';
|
||||||
import 'platform.dart';
|
import 'utils/platform.dart';
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
Log.i("App init!");
|
Log.i("App init!");
|
||||||
|
@ -2,8 +2,8 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:openmediacentermobile/types/actor.dart';
|
import 'package:openmediacentermobile/types/actor.dart';
|
||||||
import 'package:openmediacentermobile/preview/actor_tile.dart';
|
import 'package:openmediacentermobile/preview/actor_tile.dart';
|
||||||
|
|
||||||
import '../DrawerPage.dart';
|
|
||||||
import '../api/actor_api.dart';
|
import '../api/actor_api.dart';
|
||||||
|
import '../drawer/my_drawer.dart';
|
||||||
import '../screen_loading.dart';
|
import '../screen_loading.dart';
|
||||||
|
|
||||||
class ActorScreen extends StatefulWidget {
|
class ActorScreen extends StatefulWidget {
|
||||||
|
@ -2,7 +2,7 @@ import 'dart:convert';
|
|||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:openmediacentermobile/preview/tag_tile.dart';
|
import 'package:openmediacentermobile/preview/tag_tile.dart';
|
||||||
import '../DrawerPage.dart';
|
import '../drawer/my_drawer.dart';
|
||||||
import '../screen_loading.dart';
|
import '../screen_loading.dart';
|
||||||
|
|
||||||
import '../api/api.dart';
|
import '../api/api.dart';
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:openmediacentermobile/utils/FileFormatter.dart';
|
import 'package:openmediacentermobile/utils/FileFormatter.dart';
|
||||||
|
|
||||||
import '../DrawerPage.dart';
|
|
||||||
import '../api/token.dart';
|
import '../api/token.dart';
|
||||||
import '../db/database.dart';
|
import '../db/database.dart';
|
||||||
|
import '../drawer/my_drawer.dart';
|
||||||
import '../login/logincontext.dart';
|
import '../login/logincontext.dart';
|
||||||
|
|
||||||
class SettingsScreen extends StatefulWidget {
|
class SettingsScreen extends StatefulWidget {
|
||||||
|
@ -2,10 +2,10 @@ import 'dart:convert';
|
|||||||
import 'dart:math';
|
import 'dart:math';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import '../DrawerPage.dart';
|
import '../drawer/my_drawer.dart';
|
||||||
import '../preview/preview_grid.dart';
|
import '../preview/preview_grid.dart';
|
||||||
import '../api/api.dart';
|
import '../api/api.dart';
|
||||||
import '../platform.dart';
|
import '../utils/platform.dart';
|
||||||
import '../types/video.dart';
|
import '../types/video.dart';
|
||||||
|
|
||||||
class ShuffleScreen extends StatefulWidget {
|
class ShuffleScreen extends StatefulWidget {
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:openmediacentermobile/DrawerPage.dart';
|
|
||||||
|
|
||||||
import '../api/api.dart';
|
import '../api/api.dart';
|
||||||
|
import '../drawer/my_drawer.dart';
|
||||||
import '../preview/preview_grid.dart';
|
import '../preview/preview_grid.dart';
|
||||||
import '../types/tag.dart';
|
import '../types/tag.dart';
|
||||||
import '../types/video.dart';
|
import '../types/video.dart';
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:openmediacentermobile/preview/actor_feed.dart';
|
import 'package:openmediacentermobile/preview/actor_feed.dart';
|
||||||
|
|
||||||
import '../platform.dart';
|
import '../utils/platform.dart';
|
||||||
import '../types/actor.dart';
|
import '../types/actor.dart';
|
||||||
|
|
||||||
class ActorTile extends StatefulWidget {
|
class ActorTile extends StatefulWidget {
|
||||||
|
@ -3,7 +3,7 @@ import 'dart:ui';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
|
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
|
||||||
|
|
||||||
import '../platform.dart';
|
import '../utils/platform.dart';
|
||||||
import '../screen_loading.dart';
|
import '../screen_loading.dart';
|
||||||
import '../types/video.dart';
|
import '../types/video.dart';
|
||||||
import 'preview_tile.dart';
|
import 'preview_tile.dart';
|
||||||
|
@ -8,7 +8,7 @@ import 'package:sqflite/sqflite.dart';
|
|||||||
import '../api/api.dart';
|
import '../api/api.dart';
|
||||||
import '../db/database.dart';
|
import '../db/database.dart';
|
||||||
import '../log/log.dart';
|
import '../log/log.dart';
|
||||||
import '../platform.dart';
|
import '../utils/platform.dart';
|
||||||
import '../types/video.dart';
|
import '../types/video.dart';
|
||||||
import '../video_screen/videoscreen.dart';
|
import '../video_screen/videoscreen.dart';
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ import 'package:flutter/material.dart';
|
|||||||
|
|
||||||
import '../api/token.dart';
|
import '../api/token.dart';
|
||||||
import '../api/video_api.dart';
|
import '../api/video_api.dart';
|
||||||
import '../platform.dart';
|
import '../utils/platform.dart';
|
||||||
import '../screen_loading.dart';
|
import '../screen_loading.dart';
|
||||||
import '../types/video.dart';
|
import '../types/video.dart';
|
||||||
import '../types/video_data.dart';
|
import '../types/video_data.dart';
|
||||||
|
Loading…
Reference in New Issue
Block a user