mirror of
https://github.com/jagandeepbrar/lunasea.git
synced 2026-08-31 12:42:34 +00:00
fix(android): correctly handle back-button to open drawer on applicable routes
This commit is contained in:
@@ -24,7 +24,7 @@ class LunaRouter {
|
||||
/// Calls `defineAllRoutes()` on all module routers that implement [LunaModuleRouter].
|
||||
void initialize() {
|
||||
router.notFoundHandler = Handler(
|
||||
handlerFunc: (context, params) => const InvalidRoutePage(),
|
||||
handlerFunc: (context, params) => InvalidRoutePage(),
|
||||
);
|
||||
router.define(
|
||||
'/',
|
||||
|
||||
@@ -27,13 +27,13 @@ class _State extends State<_Widget> with LunaScrollControllerMixin {
|
||||
return LunaScaffold(
|
||||
scaffoldKey: _scaffoldKey,
|
||||
module: LunaModule.EXTERNAL_MODULES,
|
||||
appBar: _appBar() as PreferredSizeWidget?,
|
||||
appBar: _appBar(),
|
||||
drawer: _drawer(),
|
||||
body: _body(),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _appBar() {
|
||||
PreferredSizeWidget _appBar() {
|
||||
return LunaAppBar(
|
||||
useDrawer: true,
|
||||
title: LunaModule.EXTERNAL_MODULES.title,
|
||||
|
||||
@@ -101,7 +101,7 @@ class _State extends State<_Widget> with LunaLoadCallbackMixin {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (widget.movieId <= 0)
|
||||
return const InvalidRoutePage(
|
||||
return InvalidRoutePage(
|
||||
title: 'Movie Details',
|
||||
message: 'Movie Not Found',
|
||||
);
|
||||
|
||||
@@ -65,7 +65,7 @@ class _State extends State<_Widget> with LunaScrollControllerMixin {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (widget.movieId <= 0) {
|
||||
return const InvalidRoutePage(
|
||||
return InvalidRoutePage(
|
||||
title: 'Releases',
|
||||
message: 'Movie Not Found',
|
||||
);
|
||||
|
||||
@@ -50,7 +50,7 @@ class _State extends State<_Widget> with LunaScrollControllerMixin {
|
||||
Widget build(BuildContext context) {
|
||||
_arguments = ModalRoute.of(context)!.settings.arguments as _Arguments?;
|
||||
if (_arguments == null) {
|
||||
return const InvalidRoutePage(
|
||||
return InvalidRoutePage(
|
||||
title: 'Custom Headers',
|
||||
message: 'Indexer Not Found',
|
||||
);
|
||||
|
||||
@@ -54,10 +54,10 @@ class _State extends State<_Widget> with LunaScrollControllerMixin {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (widget.indexerId < 0)
|
||||
return const InvalidRoutePage(
|
||||
return InvalidRoutePage(
|
||||
title: 'Edit Indexer', message: 'Indexer Not Found');
|
||||
if (!LunaBox.indexers.contains(widget.indexerId))
|
||||
return const InvalidRoutePage(
|
||||
return InvalidRoutePage(
|
||||
title: 'Edit Indexer', message: 'Indexer Not Found');
|
||||
return LunaScaffold(
|
||||
scaffoldKey: _scaffoldKey,
|
||||
|
||||
@@ -54,7 +54,7 @@ class _State extends State<_Widget> with LunaScrollControllerMixin {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (widget.indexerId < 0 || !LunaBox.indexers.contains(widget.indexerId)) {
|
||||
return const InvalidRoutePage(
|
||||
return InvalidRoutePage(
|
||||
title: 'Custom Headers',
|
||||
message: 'Indexer Not Found',
|
||||
);
|
||||
|
||||
@@ -35,7 +35,7 @@ class _State extends State<_Widget> {
|
||||
scaffoldKey: _scaffoldKey,
|
||||
module: LunaModule.TAUTULLI,
|
||||
drawer: _drawer(),
|
||||
appBar: _appBar() as PreferredSizeWidget?,
|
||||
appBar: _appBar(),
|
||||
bottomNavigationBar: _bottomNavigationBar(),
|
||||
body: _body(),
|
||||
);
|
||||
@@ -49,7 +49,7 @@ class _State extends State<_Widget> {
|
||||
return null;
|
||||
}
|
||||
|
||||
Widget _appBar() {
|
||||
PreferredSizeWidget _appBar() {
|
||||
List<String> profiles = LunaBox.profiles.keys.fold([], (value, element) {
|
||||
if (LunaBox.profiles.read(element)?.tautulliEnabled ?? false)
|
||||
value.add(element);
|
||||
|
||||
@@ -2,10 +2,11 @@ import 'package:flutter/material.dart';
|
||||
import 'package:lunasea/core.dart';
|
||||
|
||||
class InvalidRoutePage extends StatelessWidget {
|
||||
final _scaffoldKey = GlobalKey<ScaffoldState>();
|
||||
final String? title;
|
||||
final String? message;
|
||||
|
||||
const InvalidRoutePage({
|
||||
InvalidRoutePage({
|
||||
Key? key,
|
||||
this.title,
|
||||
this.message,
|
||||
@@ -14,6 +15,7 @@ class InvalidRoutePage extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return LunaScaffold(
|
||||
scaffoldKey: _scaffoldKey,
|
||||
appBar: LunaAppBar(
|
||||
title: title ?? 'LunaSea',
|
||||
scrollControllers: const [],
|
||||
|
||||
@@ -4,7 +4,7 @@ import 'package:lunasea/modules.dart';
|
||||
import 'package:lunasea/system/platform.dart';
|
||||
|
||||
class LunaScaffold extends StatelessWidget {
|
||||
final GlobalKey<ScaffoldState>? scaffoldKey;
|
||||
final GlobalKey<ScaffoldState> scaffoldKey;
|
||||
final LunaModule? module;
|
||||
final PreferredSizeWidget? appBar;
|
||||
final Widget? body;
|
||||
@@ -19,7 +19,7 @@ class LunaScaffold extends StatelessWidget {
|
||||
|
||||
// ignore: use_key_in_widget_constructors
|
||||
const LunaScaffold({
|
||||
this.scaffoldKey,
|
||||
required this.scaffoldKey,
|
||||
this.module,
|
||||
this.appBar,
|
||||
this.body,
|
||||
@@ -33,15 +33,16 @@ class LunaScaffold extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final state = scaffoldKey?.currentState;
|
||||
final hasDrawer = state?.hasDrawer ?? false;
|
||||
|
||||
if (hasDrawer && LunaPlatform.isAndroid) {
|
||||
if (LunaPlatform.isAndroid) {
|
||||
return WillPopScope(
|
||||
onWillPop: () async {
|
||||
if (state!.isDrawerOpen) return true;
|
||||
state.openDrawer();
|
||||
return false;
|
||||
final state = scaffoldKey.currentState;
|
||||
if (state?.hasDrawer ?? false) {
|
||||
if (state!.isDrawerOpen) return true;
|
||||
state.openDrawer();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
child: scaffold,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user