当我使用Navigator.of(context).pushNamed('/abc');
实现新画面的动画时,
我收到如下错误:
错误:参数类型'动画'不能 分配给参数类型“动画”。 ([mhtportal_notifications]的argument_type_not_assignable LIB \ main.dart:194)
代码块(Class)如下:
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
答案 0 :(得分:1)
问题是,当动画需要FractionalOffset
时,您正在使用Offset
。
我认为您正在寻找的是:
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,
)
),
);
sa flutter bug关于这个问题(自关闭以来)提供了更多信息 - 特别是在{flixter论坛上this post,它提供了有关此更改及其原因的更多信息。