Skip to content
This repository was archived by the owner on Apr 3, 2025. It is now read-only.

Commit c91ba2c

Browse files
committed
fix(android): correctly handle back-button to open drawer on applicable routes
1 parent df65f53 commit c91ba2c

File tree

10 files changed

+24
-21
lines changed

10 files changed

+24
-21
lines changed

lib/deprecated/router/router.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class LunaRouter {
2424
/// Calls `defineAllRoutes()` on all module routers that implement [LunaModuleRouter].
2525
void initialize() {
2626
router.notFoundHandler = Handler(
27-
handlerFunc: (context, params) => const InvalidRoutePage(),
27+
handlerFunc: (context, params) => InvalidRoutePage(),
2828
);
2929
router.define(
3030
'/',

lib/modules/external_modules/routes/external_modules/route.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ class _State extends State<_Widget> with LunaScrollControllerMixin {
2727
return LunaScaffold(
2828
scaffoldKey: _scaffoldKey,
2929
module: LunaModule.EXTERNAL_MODULES,
30-
appBar: _appBar() as PreferredSizeWidget?,
30+
appBar: _appBar(),
3131
drawer: _drawer(),
3232
body: _body(),
3333
);
3434
}
3535

36-
Widget _appBar() {
36+
PreferredSizeWidget _appBar() {
3737
return LunaAppBar(
3838
useDrawer: true,
3939
title: LunaModule.EXTERNAL_MODULES.title,

lib/modules/radarr/routes/movie_details/route.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class _State extends State<_Widget> with LunaLoadCallbackMixin {
101101
@override
102102
Widget build(BuildContext context) {
103103
if (widget.movieId <= 0)
104-
return const InvalidRoutePage(
104+
return InvalidRoutePage(
105105
title: 'Movie Details',
106106
message: 'Movie Not Found',
107107
);

lib/modules/radarr/routes/releases/route.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class _State extends State<_Widget> with LunaScrollControllerMixin {
6565
@override
6666
Widget build(BuildContext context) {
6767
if (widget.movieId <= 0) {
68-
return const InvalidRoutePage(
68+
return InvalidRoutePage(
6969
title: 'Releases',
7070
message: 'Movie Not Found',
7171
);

lib/modules/settings/routes/configuration_search/pages/add_indexer_headers.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class _State extends State<_Widget> with LunaScrollControllerMixin {
5050
Widget build(BuildContext context) {
5151
_arguments = ModalRoute.of(context)!.settings.arguments as _Arguments?;
5252
if (_arguments == null) {
53-
return const InvalidRoutePage(
53+
return InvalidRoutePage(
5454
title: 'Custom Headers',
5555
message: 'Indexer Not Found',
5656
);

lib/modules/settings/routes/configuration_search/pages/edit_indexer.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ class _State extends State<_Widget> with LunaScrollControllerMixin {
5454
@override
5555
Widget build(BuildContext context) {
5656
if (widget.indexerId < 0)
57-
return const InvalidRoutePage(
57+
return InvalidRoutePage(
5858
title: 'Edit Indexer', message: 'Indexer Not Found');
5959
if (!LunaBox.indexers.contains(widget.indexerId))
60-
return const InvalidRoutePage(
60+
return InvalidRoutePage(
6161
title: 'Edit Indexer', message: 'Indexer Not Found');
6262
return LunaScaffold(
6363
scaffoldKey: _scaffoldKey,

lib/modules/settings/routes/configuration_search/pages/edit_indexer_headers.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class _State extends State<_Widget> with LunaScrollControllerMixin {
5454
@override
5555
Widget build(BuildContext context) {
5656
if (widget.indexerId < 0 || !LunaBox.indexers.contains(widget.indexerId)) {
57-
return const InvalidRoutePage(
57+
return InvalidRoutePage(
5858
title: 'Custom Headers',
5959
message: 'Indexer Not Found',
6060
);

lib/modules/tautulli/routes/tautulli/route.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class _State extends State<_Widget> {
3535
scaffoldKey: _scaffoldKey,
3636
module: LunaModule.TAUTULLI,
3737
drawer: _drawer(),
38-
appBar: _appBar() as PreferredSizeWidget?,
38+
appBar: _appBar(),
3939
bottomNavigationBar: _bottomNavigationBar(),
4040
body: _body(),
4141
);
@@ -49,7 +49,7 @@ class _State extends State<_Widget> {
4949
return null;
5050
}
5151

52-
Widget _appBar() {
52+
PreferredSizeWidget _appBar() {
5353
List<String> profiles = LunaBox.profiles.keys.fold([], (value, element) {
5454
if (LunaBox.profiles.read(element)?.tautulliEnabled ?? false)
5555
value.add(element);

lib/widgets/pages/invalid_route.dart

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import 'package:flutter/material.dart';
22
import 'package:lunasea/core.dart';
33

44
class InvalidRoutePage extends StatelessWidget {
5+
final _scaffoldKey = GlobalKey<ScaffoldState>();
56
final String? title;
67
final String? message;
78

8-
const InvalidRoutePage({
9+
InvalidRoutePage({
910
Key? key,
1011
this.title,
1112
this.message,
@@ -14,6 +15,7 @@ class InvalidRoutePage extends StatelessWidget {
1415
@override
1516
Widget build(BuildContext context) {
1617
return LunaScaffold(
18+
scaffoldKey: _scaffoldKey,
1719
appBar: LunaAppBar(
1820
title: title ?? 'LunaSea',
1921
scrollControllers: const [],

lib/widgets/ui/scaffold.dart

+10-9
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import 'package:lunasea/modules.dart';
44
import 'package:lunasea/system/platform.dart';
55

66
class LunaScaffold extends StatelessWidget {
7-
final GlobalKey<ScaffoldState>? scaffoldKey;
7+
final GlobalKey<ScaffoldState> scaffoldKey;
88
final LunaModule? module;
99
final PreferredSizeWidget? appBar;
1010
final Widget? body;
@@ -19,7 +19,7 @@ class LunaScaffold extends StatelessWidget {
1919

2020
// ignore: use_key_in_widget_constructors
2121
const LunaScaffold({
22-
this.scaffoldKey,
22+
required this.scaffoldKey,
2323
this.module,
2424
this.appBar,
2525
this.body,
@@ -33,15 +33,16 @@ class LunaScaffold extends StatelessWidget {
3333

3434
@override
3535
Widget build(BuildContext context) {
36-
final state = scaffoldKey?.currentState;
37-
final hasDrawer = state?.hasDrawer ?? false;
38-
39-
if (hasDrawer && LunaPlatform.isAndroid) {
36+
if (LunaPlatform.isAndroid) {
4037
return WillPopScope(
4138
onWillPop: () async {
42-
if (state!.isDrawerOpen) return true;
43-
state.openDrawer();
44-
return false;
39+
final state = scaffoldKey.currentState;
40+
if (state?.hasDrawer ?? false) {
41+
if (state!.isDrawerOpen) return true;
42+
state.openDrawer();
43+
return false;
44+
}
45+
return true;
4546
},
4647
child: scaffold,
4748
);

0 commit comments

Comments
 (0)