File tree Expand file tree Collapse file tree 4 files changed +33
-21
lines changed
Expand file tree Collapse file tree 4 files changed +33
-21
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ import 'package:tsdm_client/utils/logger.dart';
2626import 'package:tsdm_client/utils/platform.dart' ;
2727import 'package:tsdm_client/utils/show_dialog.dart' ;
2828import 'package:tsdm_client/utils/show_toast.dart' ;
29+ import 'package:tsdm_client/widgets/safe_pop_scope.dart' ;
2930import 'package:tsdm_client/widgets/shutdown.dart' ;
3031
3132const _drawerWidth = 250.0 ;
@@ -278,7 +279,7 @@ class _HomePageState extends State<HomePage> with LoggerMixin {
278279 // Unreachable
279280 return ;
280281 },
281- child: child,
282+ child: SafePopScope (path : '<Home Page>' , child: child) ,
282283 );
283284 },
284285 ),
Original file line number Diff line number Diff line change @@ -76,10 +76,4 @@ final class RootLocationCubit extends Cubit<RootLocationState> with LoggerMixin
7676 await _sub.cancel ();
7777 return super .close ();
7878 }
79-
80- @override
81- void onChange (Change <RootLocationState > change) {
82- super .onChange (change);
83- warning ('>>> $change ' );
84- }
8579}
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
22import 'package:tsdm_client/features/root/models/models.dart' ;
33import 'package:tsdm_client/features/root/stream/root_location_stream.dart' ;
44import 'package:tsdm_client/utils/logger.dart' ;
5- import 'package:tsdm_client/widgets/shutdown .dart' ;
5+ import 'package:tsdm_client/widgets/safe_pop_scope .dart' ;
66
77/// A top-level wrapper page for showing messages or provide functionalities to
88/// all pages across the app.
@@ -29,18 +29,6 @@ class _RootPageState extends State<RootPage> with LoggerMixin {
2929
3030 @override
3131 Widget build (BuildContext context) {
32- return BackButtonListener (
33- onBackButtonPressed: () async {
34- // App wide popping events interceptor, handles all popping events and notify the listener above.
35- rootLocationStream.add (const RootLocationEventLeavingLast ());
36- if (! context.mounted) {
37- // Well, leave it here.
38- await exitApp ();
39- return true ;
40- }
41- return true ;
42- },
43- child: widget.child,
44- );
32+ return SafePopScope (path: widget.path, child: widget.child);
4533 }
4634}
Original file line number Diff line number Diff line change 1+ import 'package:flutter/material.dart' ;
2+ import 'package:tsdm_client/features/root/models/models.dart' ;
3+ import 'package:tsdm_client/features/root/stream/root_location_stream.dart' ;
4+
5+ /// Wrapper widget handle page popping events.
6+ class SafePopScope extends StatelessWidget {
7+ /// Constructor.
8+ const SafePopScope ({required this .path, required this .child, super .key});
9+
10+ /// Route path of [child] page.
11+ final String path;
12+
13+ /// Wrapped child widget.
14+ final Widget child;
15+
16+ @override
17+ Widget build (BuildContext context) {
18+ return PopScope (
19+ canPop: false ,
20+ onPopInvokedWithResult: (didPop, b) {
21+ if (! didPop) {
22+ // When popping event passed location check, `didPop` is true, do not recursively handle it.
23+ rootLocationStream.add (const RootLocationEventLeavingLast ());
24+ }
25+ },
26+ child: child,
27+ );
28+ }
29+ }
You can’t perform that action at this time.
0 commit comments