-
Notifications
You must be signed in to change notification settings - Fork 0
/
sliding_push_route.dart
36 lines (27 loc) · 1.19 KB
/
sliding_push_route.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import 'package:flutter/widgets.dart';
import '../../coordinated_page_route.dart';
/// A [CoordinatedPageRoute] that pushes the old route out in the same direction that the new route comes in according to some [initialOffset].
abstract class SlidingPushRoute extends CoordinatedPageRoute {
SlidingPushRoute(super.builder, {this.curve = Curves.easeInOut});
final Curve curve;
@override
Widget Function(BuildContext context, Widget child)
get entryTransitionBuilder => (context, child) =>
_getSlideTransition(child, initialOffset, Offset.zero);
@override
Widget Function(BuildContext context, Widget child)
get exitTransitionBuilder => (context, child) =>
_getSlideTransition(child, Offset.zero, -initialOffset);
SlideTransition _getSlideTransition(Widget child, Offset from, Offset to) {
return SlideTransition(
position: _getCurvedOffsetAnimation(from, to),
child: child,
);
}
Animation<Offset> _getCurvedOffsetAnimation(Offset from, Offset to) {
return CurvedAnimation(parent: animation, curve: curve)
.drive(Tween(begin: from, end: to));
}
/// The offset at which the newRoute begins its entry.
Offset get initialOffset;
}