[go_router] Adds `reverseTransitionDuration` to `CustomTransitionPage` (#3175)
* Add reverseTransitionDuration to CustomTransitionPage
* remove hero widget from example and modify some tests
* fix test for reverseTransitionDuration
* update version to 6.0.5
* update version to 6.0.6
diff --git a/packages/go_router/CHANGELOG.md b/packages/go_router/CHANGELOG.md
index 9b01db8..bf7bfe9 100644
--- a/packages/go_router/CHANGELOG.md
+++ b/packages/go_router/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 6.0.6
+
+- Adds `reverseTransitionDuration` to `CustomTransitionPage`
+
## 6.0.5
- Fixes [unnecessary_null_comparison](https://dart-lang.github.io/linter/lints/unnecessary_null_checks.html) lint warnings.
diff --git a/packages/go_router/example/lib/transition_animations.dart b/packages/go_router/example/lib/transition_animations.dart
index 0082cb5..5c13fef 100644
--- a/packages/go_router/example/lib/transition_animations.dart
+++ b/packages/go_router/example/lib/transition_animations.dart
@@ -58,6 +58,29 @@
);
},
),
+ GoRoute(
+ path: 'custom-reverse-transition-duration',
+ pageBuilder: (BuildContext context, GoRouterState state) {
+ return CustomTransitionPage<void>(
+ key: state.pageKey,
+ child: const DetailsScreen(),
+ barrierDismissible: true,
+ barrierColor: Colors.black38,
+ opaque: false,
+ transitionDuration: const Duration(milliseconds: 500),
+ reverseTransitionDuration: const Duration(milliseconds: 200),
+ transitionsBuilder: (BuildContext context,
+ Animation<double> animation,
+ Animation<double> secondaryAnimation,
+ Widget child) {
+ return FadeTransition(
+ opacity: animation,
+ child: child,
+ );
+ },
+ );
+ },
+ ),
],
),
],
@@ -98,6 +121,14 @@
onPressed: () => context.go('/dismissible-details'),
child: const Text('Go to the Dismissible Details screen'),
),
+ const SizedBox(height: 48),
+ ElevatedButton(
+ onPressed: () =>
+ context.go('/custom-reverse-transition-duration'),
+ child: const Text(
+ 'Go to the Custom Reverse Transition Duration Screen',
+ ),
+ ),
],
),
),
diff --git a/packages/go_router/lib/src/pages/custom_transition_page.dart b/packages/go_router/lib/src/pages/custom_transition_page.dart
index 38bde2c..3993a9c 100644
--- a/packages/go_router/lib/src/pages/custom_transition_page.dart
+++ b/packages/go_router/lib/src/pages/custom_transition_page.dart
@@ -17,6 +17,7 @@
required this.child,
required this.transitionsBuilder,
this.transitionDuration = const Duration(milliseconds: 300),
+ this.reverseTransitionDuration = const Duration(milliseconds: 300),
this.maintainState = true,
this.fullscreenDialog = false,
this.opaque = true,
@@ -38,6 +39,12 @@
/// Defaults to 300ms.
final Duration transitionDuration;
+ /// A duration argument to customize the duration of the custom page
+ /// transition on pop.
+ ///
+ /// Defaults to 300ms.
+ final Duration reverseTransitionDuration;
+
/// Whether the route should remain in memory when it is inactive.
///
/// If this is true, then the route is maintained, so that any futures it is
@@ -119,6 +126,9 @@
Duration get transitionDuration => _page.transitionDuration;
@override
+ Duration get reverseTransitionDuration => _page.reverseTransitionDuration;
+
+ @override
bool get maintainState => _page.maintainState;
@override
diff --git a/packages/go_router/pubspec.yaml b/packages/go_router/pubspec.yaml
index 6d25812..a135920 100644
--- a/packages/go_router/pubspec.yaml
+++ b/packages/go_router/pubspec.yaml
@@ -1,7 +1,7 @@
name: go_router
description: A declarative router for Flutter based on Navigation 2 supporting
deep linking, data-driven routes and more
-version: 6.0.5
+version: 6.0.6
repository: https://github.com/flutter/packages/tree/main/packages/go_router
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+go_router%22
diff --git a/packages/go_router/test/custom_transition_page_test.dart b/packages/go_router/test/custom_transition_page_test.dart
index b93fd21..caf8fd4 100644
--- a/packages/go_router/test/custom_transition_page_test.dart
+++ b/packages/go_router/test/custom_transition_page_test.dart
@@ -117,6 +117,47 @@
await tester.pumpAndSettle();
expect(find.byKey(homeKey), findsOneWidget);
});
+
+ testWidgets('transitionDuration and reverseTransitionDuration is different',
+ (WidgetTester tester) async {
+ const ValueKey<String> homeKey = ValueKey<String>('home');
+ const ValueKey<String> loginKey = ValueKey<String>('login');
+ const Duration transitionDuration = Duration(milliseconds: 50);
+ const Duration reverseTransitionDuration = Duration(milliseconds: 500);
+
+ final GoRouter router = GoRouter(
+ routes: <GoRoute>[
+ GoRoute(
+ path: '/',
+ builder: (_, __) => const HomeScreen(key: homeKey),
+ ),
+ GoRoute(
+ path: '/login',
+ pageBuilder: (_, GoRouterState state) => CustomTransitionPage<void>(
+ key: state.pageKey,
+ transitionDuration: transitionDuration,
+ reverseTransitionDuration: reverseTransitionDuration,
+ transitionsBuilder:
+ (_, Animation<double> animation, ___, Widget child) =>
+ FadeTransition(opacity: animation, child: child),
+ child: const LoginScreen(key: loginKey),
+ ),
+ ),
+ ],
+ );
+ await tester.pumpWidget(MaterialApp.router(routerConfig: router));
+ expect(find.byKey(homeKey), findsOneWidget);
+
+ router.push('/login');
+ final int pushingPumped = await tester.pumpAndSettle();
+ expect(find.byKey(loginKey), findsOneWidget);
+
+ router.pop();
+ final int poppingPumped = await tester.pumpAndSettle();
+ expect(find.byKey(homeKey), findsOneWidget);
+
+ expect(pushingPumped != poppingPumped, true);
+ });
}
class HomeScreen extends StatelessWidget {