Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ BeamPageType ] Added slideRightTransition , slideLeftTransition , slideTopTransition #477

Merged
merged 2 commits into from
Feb 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions package/lib/src/beam_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 top transition.
slideTopTransition,

/// An enum for a page type with scale transition.
scaleTransition,

Expand Down Expand Up @@ -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,
Expand Down
42 changes: 42 additions & 0 deletions package/test/beam_page_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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')),
),
},
),
);
Expand Down Expand Up @@ -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 {
Expand Down