diff --git a/CHANGELOG.md b/CHANGELOG.md index 06951ff..2060ec3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 0.2.0 +- Update GoRouter to v16.0.0 +- Update minimum Dart SDK version to 3.6.0 and Flutter SDK version to 3.27.0 +- Refactored `PlayxRoute` and `PlayxNavigationBuilder` to better handle route state and binding events. +- `GoRouterState` now passed correctly to `onReEnter`. + ## 0.1.2 - Update GoRouter to v14.8.1 - Add `setupWeb` method for `PlayxNavigation` which allows for using path-based URLs and enables URL-based imperative APIs diff --git a/example/pubspec.lock b/example/pubspec.lock index 13d4746..cd1efa8 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -5,10 +5,10 @@ packages: dependency: transitive description: name: async - sha256: d2872f9c19731c2e5f10444b14686eb7cc85c76274bd6c16e1816bff9a3bab63 + sha256: "758e6d74e971c3e5aceb4110bfd6698efc7f501675bcfe0c775459a8140750eb" url: "https://pub.dev" source: hosted - version: "2.12.0" + version: "2.13.0" boolean_selector: dependency: transitive description: @@ -53,10 +53,10 @@ packages: dependency: transitive description: name: fake_async - sha256: "6a95e56b2449df2273fd8c45a662d6947ce1ebb7aafe80e550a3f68297f3cacc" + sha256: "5368f224a74523e8d2e7399ea1638b37aecfca824a3cc4dfdf77bf1fa905ac44" url: "https://pub.dev" source: hosted - version: "1.3.2" + version: "1.3.3" flutter: dependency: "direct main" description: flutter @@ -84,18 +84,18 @@ packages: dependency: transitive description: name: go_router - sha256: f02fd7d2a4dc512fec615529824fdd217fecb3a3d3de68360293a551f21634b3 + sha256: c489908a54ce2131f1d1b7cc631af9c1a06fac5ca7c449e959192089f9489431 url: "https://pub.dev" source: hosted - version: "14.8.1" + version: "16.0.0" leak_tracker: dependency: transitive description: name: leak_tracker - sha256: c35baad643ba394b40aac41080300150a4f08fd0fd6a10378f8f7c6bc161acec + sha256: "6bb818ecbdffe216e81182c2f0714a2e62b593f4a4f13098713ff1685dfb6ab0" url: "https://pub.dev" source: hosted - version: "10.0.8" + version: "10.0.9" leak_tracker_flutter_testing: dependency: transitive description: @@ -166,7 +166,7 @@ packages: path: ".." relative: true source: path - version: "0.1.2" + version: "0.2.0" sky_engine: dependency: transitive description: flutter @@ -232,10 +232,10 @@ packages: dependency: transitive description: name: vm_service - sha256: "0968250880a6c5fe7edc067ed0a13d4bae1577fe2771dcf3010d52c4a9d3ca14" + sha256: ddfa8d30d89985b96407efce8acbdd124701f96741f2d981ca860662f1c0dc02 url: "https://pub.dev" source: hosted - version: "14.3.1" + version: "15.0.0" sdks: dart: ">=3.7.0-0 <4.0.0" - flutter: ">=3.22.0" + flutter: ">=3.27.0" diff --git a/lib/src/router/playx_router.dart b/lib/src/router/playx_router.dart index f8cc406..b5cbc20 100644 --- a/lib/src/router/playx_router.dart +++ b/lib/src/router/playx_router.dart @@ -20,16 +20,16 @@ class PlayxRouter { /// Gets the current [GoRouterState] object representing the current state of the /// navigation stack. - GoRouterState? get state => router.state; + GoRouterState get state => router.state; /// Gets the current [GoRoute] object representing the current route in the /// navigation stack. - GoRoute? get currentRoute => state?.topRoute; + GoRoute? get currentRoute => state.topRoute; /// Gets the name of the current route, if available. /// /// Returns `null` if there is no current route or if the route has no name. - String? get currentRouteName => state?.name; + String? get currentRouteName => state.name; /// Adds a listener for route changes. /// @@ -41,7 +41,9 @@ class PlayxRouter { /// Removes a previously added route change listener. /// /// The provided [listener] will no longer be called when the route changes. - void removeRouteChangeListener(VoidCallback listener) + void removeRouteChangeListener(VoidCallback listener) { + router.routerDelegate.removeListener(listener); + } /// Navigate to the current location of the branch at the provided index of /// [StatefulShellRoute]. @@ -53,10 +55,6 @@ class PlayxRouter { /// When navigating to a new branch, it's recommended to use the goToBranch /// method, as doing so makes sure the last navigation state of the /// Navigator for the branch is restored. - { - router.routerDelegate.removeListener(listener); - } - void goToBranch({ required int index, required StatefulNavigationShell navigationShell, diff --git a/lib/src/routes/playx_route.dart b/lib/src/routes/playx_route.dart index 97cc37b..1d05261 100644 --- a/lib/src/routes/playx_route.dart +++ b/lib/src/routes/playx_route.dart @@ -95,23 +95,33 @@ class PlayxRoute extends GoRoute { if (binding == null) return null; final topRoute = state.topRoute; + + // If the current route is no longer on top, call onExit if needed + if (topRoute == null || topRoute.path != path) { + if (binding.shouldExecuteOnExit) { + await binding.onExit(context); + } + return null; + } + // Trigger onEnter when entering the page for the first time and when the top route is the same as the current route // We need to fire onEnter here so we can have access to the route state. - if (topRoute == null || path == topRoute.path) { - final pageState = binding.currentState; - if (pageState == null || pageState == PlayxPageState.exit) { - binding.onEnter(context, state); - binding.currentState = PlayxPageState.enter; - } else { - binding.onReEnter( - context, - state, - false, - ); - binding.currentState = PlayxPageState.reEnter; - } - binding.shouldExecuteOnExit = false; - } else {} + final pageState = binding.currentState; + final isFirstEnter = + pageState == null || pageState == PlayxPageState.exit; + binding.currentState = + isFirstEnter ? PlayxPageState.enter : PlayxPageState.reEnter; + + if (isFirstEnter) { + binding.onEnter(context, state); + } else { + binding.onReEnter( + context, + state, + false, + ); + } + binding.shouldExecuteOnExit = false; return null; }, onExit: binding == null diff --git a/lib/src/widgets/playx_navigation_builder.dart b/lib/src/widgets/playx_navigation_builder.dart index 4ab7ed6..b4c9762 100644 --- a/lib/src/widgets/playx_navigation_builder.dart +++ b/lib/src/widgets/playx_navigation_builder.dart @@ -95,7 +95,9 @@ class _PlayxNavigationBuilderState extends State { if (currentBinding != null) { if (currentBinding.currentState != PlayxPageState.enter && currentBinding.currentState != PlayxPageState.reEnter) { - currentBinding.onReEnter(context, null, true); + final GoRouterState newState = + PlayxNavigation.goRouter.routerDelegate.state; + currentBinding.onReEnter(context, newState, true); currentBinding.currentState = PlayxPageState.reEnter; } } diff --git a/pubspec.yaml b/pubspec.yaml index 53139a3..f7878d2 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: playx_navigation description: Playx Navigation is a Flutter package that enhances app navigation with advanced features like route lifecycle management, custom transitions, and flexible configuration. -version: 0.1.2 +version: 0.2.0 homepage: https://sourcya.io repository: https://github.com/playx-flutter/playx_navigation issue_tracker: https://github.com/playx-flutter/playx_navigation/issues @@ -12,8 +12,8 @@ topics: - route-management environment: - sdk: '>=3.3.0 <4.0.0' - flutter: ">=3.19.0" + sdk: '>=3.6.0 <4.0.0' + flutter: ">=3.27.0" dependencies: @@ -21,10 +21,10 @@ dependencies: sdk: flutter flutter_web_plugins: sdk: flutter - go_router: ^14.8.1 + go_router: ^16.0.0 dev_dependencies: flutter_test: sdk: flutter - flutter_lints: ^5.0.0 + flutter_lints: ^6.0.0