From 3c7d4847ae7e6ac100f331f7794a95bfb499636c Mon Sep 17 00:00:00 2001 From: Shiba-Kar Date: Sat, 12 Feb 2022 00:05:10 +0530 Subject: [PATCH 1/2] [ BeamPageType ] slideRightTransition , slideLeftTransition , slideTopTransition --- package/lib/src/beam_page.dart | 48 ++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/package/lib/src/beam_page.dart b/package/lib/src/beam_page.dart index 01fb81d5..ad0fd8e9 100644 --- a/package/lib/src/beam_page.dart +++ b/package/lib/src/beam_page.dart @@ -19,6 +19,15 @@ enum BeamPageType { /// An enum for a page type with slide transition. slideTransition, + /// An enum for a page type with slide right transition. + slideRightTransition, + + /// An enum for a page type with slide left transition. + slideLeftTransition, + + /// An enum for a page type with slide left transition. + slideTopTransition, + /// An enum for a page type with scale transition. scaleTransition, @@ -261,6 +270,45 @@ class BeamPage extends Page { child: child, ), ); + case BeamPageType.slideRightTransition: + return PageRouteBuilder( + fullscreenDialog: fullScreenDialog, + opaque: opaque, + settings: this, + pageBuilder: (_, __, ___) => child, + transitionsBuilder: (_, animation, __, child) => SlideTransition( + position: animation.drive( + Tween(begin: const Offset(1, 0), end: const Offset(0, 0)) + .chain(CurveTween(curve: Curves.ease))), + child: child, + ), + ); + case BeamPageType.slideLeftTransition: + return PageRouteBuilder( + fullscreenDialog: fullScreenDialog, + opaque: opaque, + settings: this, + pageBuilder: (_, __, ___) => child, + transitionsBuilder: (_, animation, __, child) => SlideTransition( + position: animation.drive( + Tween(begin: const Offset(-1, 0), end: const Offset(0, 0)) + .chain(CurveTween(curve: Curves.ease))), + child: child, + ), + ); + case BeamPageType.slideTopTransition: + return PageRouteBuilder( + fullscreenDialog: fullScreenDialog, + opaque: opaque, + settings: this, + pageBuilder: (_, __, ___) => child, + transitionsBuilder: (_, animation, __, child) => SlideTransition( + position: animation.drive( + Tween(begin: const Offset(0, -1), end: const Offset(0, 0)) + .chain(CurveTween(curve: Curves.ease))), + child: child, + ), + ); case BeamPageType.scaleTransition: return PageRouteBuilder( fullscreenDialog: fullScreenDialog, From 6b701a9cf76e3399e6778f4650a1d9921a18a694 Mon Sep 17 00:00:00 2001 From: Shiba-Kar Date: Sun, 13 Feb 2022 11:07:09 +0530 Subject: [PATCH 2/2] tests and a typo --- package/lib/src/beam_page.dart | 2 +- package/test/beam_page_test.dart | 42 ++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/package/lib/src/beam_page.dart b/package/lib/src/beam_page.dart index ad0fd8e9..b0845f98 100644 --- a/package/lib/src/beam_page.dart +++ b/package/lib/src/beam_page.dart @@ -25,7 +25,7 @@ enum BeamPageType { /// An enum for a page type with slide left transition. slideLeftTransition, - /// An enum for a page type with slide left transition. + /// An enum for a page type with slide top transition. slideTopTransition, /// An enum for a page type with scale transition. diff --git a/package/test/beam_page_test.dart b/package/test/beam_page_test.dart index 7f7ca950..973395c2 100644 --- a/package/test/beam_page_test.dart +++ b/package/test/beam_page_test.dart @@ -523,6 +523,21 @@ void main() { ), child: const Text('Child'), ), + '/1/2/3/4/5/6/7': (context, state, data) => const BeamPage( + key: ValueKey('/1/2/3/4/5/6/7'), + type: BeamPageType.slideRightTransition, + child: Scaffold(body: Text('7')), + ), + '/1/2/3/4/5/6/7/8': (context, state, data) => const BeamPage( + key: ValueKey('/1/2/3/4/5/6/7/8'), + type: BeamPageType.slideLeftTransition, + child: Scaffold(body: Text('8')), + ), + '/1/2/3/4/5/6/7/8/9': (context, state, data) => const BeamPage( + key: ValueKey('/1/2/3/4/5/6/7/8/9'), + type: BeamPageType.slideTopTransition, + child: Scaffold(body: Text('9')), + ), }, ), ); @@ -577,6 +592,33 @@ void main() { await tester.pump(); expect(find.text('6'), findsOneWidget); expect(find.text('Child'), findsOneWidget); + + delegate.beamToNamed('/1/2/3/4/5/6/7'); + await tester.pump(); + await tester.pump(const Duration(milliseconds: 8)); + offset = tester.getTopLeft(find.text('7')); + expect(offset.dx, greaterThan(0.0)); + expect(offset.dx, lessThan(800.0)); + expect(offset.dy, equals(0.0)); + expect(offset.dy, equals(0.0)); + + delegate.beamToNamed('/1/2/3/4/5/6/7/8'); + await tester.pump(); + await tester.pump(const Duration(milliseconds: 8)); + offset = tester.getTopLeft(find.text('8')); + expect(offset.dx, greaterThan(-800.0)); + expect(offset.dx, lessThan(0.0)); + expect(offset.dy, equals(0.0)); + expect(offset.dy, equals(0.0)); + + delegate.beamToNamed('/1/2/3/4/5/6/7/8/9'); + await tester.pump(); + await tester.pump(const Duration(milliseconds: 8)); + offset = tester.getTopLeft(find.text('9')); + expect(offset.dx, equals(0.0)); + expect(offset.dx, equals(0.0)); + expect(offset.dy, greaterThan(-600.0)); + expect(offset.dy, lessThan(0.0)); }); testWidgets('pageless no animation transition', (tester) async {