【问题标题】:Drawer Animation Error :'Animation<FractionalOffset>' can't be assigned to the parameter type 'Animation<Offset>'抽屉动画错误:'Animation<FractionalOffset>' 不能分配给参数类型'Animation<Offset>'
【发布时间】:2018-04-06 17:28:14
【问题描述】:

当我使用 Navigator.of(context).pushNamed('/abc'); 为新屏幕实现动画时,
我收到如下错误:

错误:参数类型“动画”​​不能是 分配给参数类型“动画”​​。 (argument_type_not_assignable 在 [mhtportal_notifications] lib\main.dart:194)

代码块(类)如下:

class FromRightToLeft<T> extends MaterialPageRoute<T> {
  FromRightToLeft({ WidgetBuilder builder, RouteSettings settings })
      : super(builder: builder, settings: settings);

  @override
  Widget buildTransitions(
      BuildContext context,
      Animation<double> animation,
      Animation<double> secondaryAnimation,
      Widget child) {

    if (settings.isInitialRoute)
      return child;

    return new SlideTransition(
      child: new Container(
        decoration: new BoxDecoration(
            boxShadow: [
              new BoxShadow(
                color: Colors.black26,
                blurRadius: 25.0,
              )
            ]
        ),
        child: child,
      ),
      position: new FractionalOffsetTween(
        begin: const FractionalOffset(1.0, 0.0),
        end: FractionalOffset.topLeft,
      )
          .animate(
          new CurvedAnimation(
            parent: animation,
            curve: Curves.fastOutSlowIn,
          )
      ),
    );
  }
  @override Duration get transitionDuration => const Duration(milliseconds: 400);
}

代码来源:GitHub

【问题讨论】:

    标签: android flutter


    【解决方案1】:

    问题是您使用的是FractionalOffset,而动画需要@9​​87654324@。

    我认为您正在寻找的是:

    return new SlideTransition(
      child: new Container(
        decoration: new BoxDecoration(
          boxShadow: [
            new BoxShadow(
              color: Colors.black26,
              blurRadius: 25.0,
            )
          ]
        ),
        child: child,
      ),
      position: new Tween(
        begin: const Offset(1.0, 0.0),
        end: const Offset(0.0, 0.0),
      )
      .animate(
        new CurvedAnimation(
          parent: animation,
          curve: Curves.fastOutSlowIn,
        )
      ),
    );
    

    有一个 flutter bug 与此有关(自关闭以来),其中包含更多信息 - 特别是颤振论坛上的 this post,提供了有关此更改及其原因的更多信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-11
      • 1970-01-01
      • 2022-01-23
      • 2021-09-21
      • 1970-01-01
      • 2021-07-05
      • 2021-10-03
      • 2022-12-27
      相关资源
      最近更新 更多