我正在尝试通过导航器自定义动画。这是我当前路线的样子:
class HelpRoute<T> extends MaterialPageRoute<T> {
HelpRoute({
WidgetBuilder builder,
}): super(builder: builder);
@override
Widget buildTransitions(BuildContext context,
Animation<double> animation,
Animation<double> secondaryAnimation,
Widget child)
{
if (settings.isInitialRoute)
return child;
return new SlideTransition(
position: new FractionalOffsetTween(
begin: FractionalOffset.topRight,
end: FractionalOffset.topLeft,
)
.animate(
new CurvedAnimation(
parent: animation,
curve: Curves.ease,
)
),
child: child,
);
}
@override Duration get transitionDuration => const Duration(milliseconds: 400);
}
并且此效果完全正常,并且从右到左逐渐消失。但是现在我想从左到右过渡。如果我将begin更改为topLeft,将end更改为topRight,则会发疯,并最终出现在黑屏中。
为了使该功能有效,我还有其他选择吗?提前致谢
最佳答案
您希望新路线完全在屏幕外开始,这是-1.0,0.0的FractionalOffset。您希望它最终以FractionalOffset 0.0,0.0,也称为FractionalOffset.topLeft
结束。如下将您的构造函数参数更改为FractionalOffsetTween
:
new FractionalOffsetTween(
begin: const FractionalOffset(-1.0, 0.0),
end: FractionalOffset.topLeft,
)