如何解决如何在 GetPage flutter 中使用自定义过渡
我有 CustomPageRoute
用于导航到具有自定义转换的新页面。
为了导航,我使用以下代码:
Navigator.push(
context,CustomPageRoute(
NewScreen(),),
这很好用,但现在我想在 getx 库中使用 GetPage
添加依赖项。
GetPage(
name: Routes.NEW_SCREEN,page: () => NewScreen(),binding: NewScreenBinding(),
所以我必须使用 Get.toNamed(Routes.NEW_SCREEN)
进行导航并且我的自定义转换不起作用。
如何将我的自定义过渡与 GetPage
这是我的自定义过渡:
class CustomPageRoute<T> extends PageRoute<T> {
final Widget child;
CustomPageRoute(this.child);
@override
Color get barrierColor => Colors.black;
@override
String get barrierLabel => '';
@override
bool get maintainState => true;
@override
Duration get transitionDuration => Duration(milliseconds: 600);
@override
Widget buildPage(
BuildContext context,Animation<double> animation,Animation<double> secondaryAnimation,) {
return FadeTransition(
opacity: animation,child: child,);
}
}
解决方法
我认为这可以更简单一些。创建一个这样的类...
class Go {
static Future<dynamic> to(dynamic page,{dynamic arguments}) async {
Get.to(
page,arguments: arguments,transition: Transition.fadeIn,// choose your page transition accordingly
duration: const Duration(milliseconds: 300),);
}
}
然后在您的视图或控制器中
Go.to(
() => OtpView(),arguments: 'your dynamic argument'
);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。