颤动 - 自定义路径转换导致黑屏

时间:2017-05-10 13:19:01

标签: routing dart flutter

我正在尝试从导航器自定义动画。这就是我目前的路线:

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);
}

这完全正常,从右到左淡入。但现在我想要从左到右过渡。如果我将开始更改为topLeft并将结束更改为topRight,它会变得疯狂并最终以黑屏结束。

为了使这项工作还有其他选择吗?提前致谢

1 个答案:

答案 0 :(得分:4)

您希望新路线完全从屏幕左侧开始,这是一个-1.0的FractionalOffset,0.0。您希望它最终得到0.0,0.0,a.k.a FractionalOffset.topLeft的FractionalOffset。将构造函数参数更改为FractionalOffsetTween,如下所示:

new FractionalOffsetTween(
    begin: const FractionalOffset(-1.0, 0.0),
    end: FractionalOffset.topLeft,
)