I have a custom PageRouteBuilder like this:
class MyRouter extends PageRouteBuilder {
final String? transitionType;
final Widget? widget;
final Widget? leavingWidget;
final RouteSettings? routeSettings;
MyRouter(
{this.transitionType,
this.widget,
this.leavingWidget,
this.routeSettings})
: super(
settings: routeSettings,
//transitionDuration: const Duration(seconds: 3),
pageBuilder: (context, animation, secondaryAnimation) => widget!,
transitionsBuilder: (context, animation, secondaryAnimation, child) {
} else if (transitionType == 'slideLeftOld') {
Stack(
children: [
SlideTransition(
position: Tween(
begin: Offset.zero,
end: Offset(-1.0, 0.0),
).animate(animation),
child: leavingWidget,
),
SlideTransition(
position: Tween(
begin: Offset(1.0, 0.0),
end: Offset.zero,
).animate(animation),
child: widget,
),
],
);
I want to animate from a old widget to a new widget with:
Route _onGenerateRoute(RouteSettings settings) {
final args = settings.arguments;
switch (settings.name) {
case '/slideLeftOld':
return MyRouter(
routeSettings: RouteSettings(name: settings.name),
widget: CalendarSwiperContent(
selectedDay: args as DateTime,
changeItems: _callbackItems,
),
leavingWidget: getCurrentWidget()
transitionType: 'slideLeftOld');
This is working but the old widget getCurrentWidget
is reloading during the animation. thats not nice.
I could do the animation with the secondaryAnimation parameter as described here: /flutter/widgets/ModalRoute/buildTransitions.html
but that doesn't give me enough flexibility, because it's difficult to control when which animation occurs. That's why I'd like to be able to control whether the animation goes from left to right or right to left.
Since I'm working with a NavigatorState, I'm wondering how I can send the state or the current widget in the navigator to the PageRouteBuilder.
await routineNavigatorKey.currentState!
.pushReplacementNamed('/slideLeftOld', arguments: dateTime);