fix(android): correctly handle back-button to open drawer on applicable routes

This commit is contained in:
Jagandeep Brar
2022-07-09 16:18:21 -04:00
parent df65f53a4b
commit c91ba2ce81
10 changed files with 24 additions and 21 deletions

View File

@@ -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(
'/',

View File

@@ -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,

View File

@@ -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',
);

View File

@@ -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',
);

View File

@@ -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',
);

View File

@@ -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,

View File

@@ -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',
);

View File

@@ -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);

View File

@@ -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 [],

View File

@@ -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,
);