Skip to content

Commit

Permalink
Merge pull request #477 from Shiba-Kar/master
Browse files Browse the repository at this point in the history
[ BeamPageType ]  Added slideRightTransition , slideLeftTransition , slideTopTransition
  • Loading branch information
slovnicki authored Feb 13, 2022
2 parents e6d6596 + 6b701a9 commit e68bb7c
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
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

0 comments on commit e68bb7c

Please sign in to comment.