From e8ba50c4d6d040abb4c45c202be0180686f354a5 Mon Sep 17 00:00:00 2001 From: foxsofter Date: Tue, 31 Oct 2023 18:16:12 +0800 Subject: [PATCH] fix: NavigatorWillPopMixin not working when pop --- CHANGELOG.md | 3 ++ .../src/biz/biz1/flutter3/flutter3.page.dart | 41 +++++++++++++++++-- .../navigator/navigator_will_pop_mixin.dart | 1 + pubspec.yaml | 2 +- 4 files changed, 42 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index be36913..91af6af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 4.6.4 +- fix: NavigatorWillPopMixin not working when pop + ## 4.6.3 - fix: push url with query parameter will not get pop result diff --git a/example/lib/src/biz/biz1/flutter3/flutter3.page.dart b/example/lib/src/biz/biz1/flutter3/flutter3.page.dart index 8dd9c29..6b70b4f 100644 --- a/example/lib/src/biz/biz1/flutter3/flutter3.page.dart +++ b/example/lib/src/biz/biz1/flutter3/flutter3.page.dart @@ -283,6 +283,25 @@ class _TestPageState extends State { ), ), ), + Padding( + padding: const EdgeInsets.all(8.0), + child: ElevatedButton( + style: ButtonStyle( + foregroundColor: + MaterialStateProperty.all(Colors.indigo)), + onPressed: () { + Navigator.of(context).push( + MaterialPageRoute( + settings: const RouteSettings(name: 'test'), + builder: (context) => const TestPage()), + ); + }, + child: const Text( + 'Navigator push 2', + style: TextStyle(color: Colors.white), + ), + ), + ), Padding( padding: const EdgeInsets.all(8.0), child: ElevatedButton( @@ -302,6 +321,22 @@ class _TestPageState extends State { ), ), ), + Padding( + padding: const EdgeInsets.all(8.0), + child: ElevatedButton( + style: ButtonStyle( + foregroundColor: + MaterialStateProperty.all(Colors.indigo)), + onPressed: () async { + final mctx = await biz.biz1.flutter1.home.push(); + ThrioLogger.v(mctx.toString()); + }, + child: const Text( + 'push thrio page', + style: TextStyle(color: Colors.white), + ), + ), + ), Padding( padding: const EdgeInsets.all(8.0), child: ElevatedButton( @@ -380,10 +415,8 @@ class _TestNavigatorPageState extends State { class TestObser extends NavigatorObserver { @override - void didPush(Route route, Route? previousRoute) { - } + void didPush(Route route, Route? previousRoute) {} @override - void didReplace({Route? newRoute, Route? oldRoute}) { - } + void didReplace({Route? newRoute, Route? oldRoute}) {} } diff --git a/lib/src/navigator/navigator_will_pop_mixin.dart b/lib/src/navigator/navigator_will_pop_mixin.dart index cfa3716..789383d 100644 --- a/lib/src/navigator/navigator_will_pop_mixin.dart +++ b/lib/src/navigator/navigator_will_pop_mixin.dart @@ -80,6 +80,7 @@ mixin NavigatorWillPopMixin on State { _added = false; _route?.removeScopedWillPopCallback(onWillPop); _route = ModalRoute.of(context); + _checkWillPop(); } void _checkWillPop() { diff --git a/pubspec.yaml b/pubspec.yaml index 2c75bd0..e7a2c6a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_thrio description: Thrio makes it easy and fast to add flutter to existing mobile applications, and provide a simple and consistent navigator APIs. -version: 4.6.3 +version: 4.6.4 homepage: https://github.com/flutter-thrio/flutter_thrio environment: