flutter - PageRouteBuilder的pageBuilder和transitionsBuilder typedef参数的区别

标签 flutter flutter-layout transition flutter-animation

根据official docs pageBuilder 参数用于构建主要路由内容,transitionsBuilder 参数用于构建路由的转换。

所以它们都有不同的工作,但是如果 pageBuilder 用于构建主要路由内容,那么为什么它还在其 typedef RoutePageBuilder 中声明了两个 Animation 参数,也在 transitionBuilder typedef RouteTransitionBuilder 中,有两个 Animation 参数声明为 animationsecondaryAnimation。 这两个 Animation 之间有什么区别以及我们如何使用它们?

最佳答案

routes.dart 中的文档:


  /// [buildPage] is only called when the route is first built, and rarely
  /// thereafter. In particular, it is not automatically called again when the
  /// route's state changes unless it uses [ModalRoute.of]. For a builder that
  /// is called every time the route's state changes, consider
  /// [buildTransitions]. For widgets that change their behavior when the
  /// route's state changes, consider [ModalRoute.of] to obtain a reference to
  /// the route; this will cause the widget to be rebuilt each time the route
  /// changes state.
  ///
  /// In general, [buildPage] should be used to build the page contents, and
  /// [buildTransitions] for the widgets that change as the page is brought in
  /// and out of view. Avoid using [buildTransitions] for content that never
  /// changes; building such content once from [buildPage] is more efficient.

  /// The [buildTransitions] method, in contrast to [buildPage], is called each
  /// time the [Route]'s state changes (e.g. the value of [canPop]).
  ///
  /// The [buildTransitions] method is typically used to define transitions
  /// that animate the new topmost route's comings and goings. When the
  /// [Navigator] pushes a route on the top of its stack, the new route's
  /// primary [animation] runs from 0.0 to 1.0. When the Navigator pops the
  /// topmost route, e.g. because the use pressed the back button, the
  /// primary animation runs from 1.0 to 0.0.

关于flutter - PageRouteBuilder的pageBuilder和transitionsBuilder typedef参数的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54229266/

相关文章:

flutter - Flutter 容器中的图标间距

当值频繁变化时(与性能无关),CSS3 转换过渡会断断续续

html - 更改 CSS 过渡的方向

firebase - 如何使用 Flutter 从 firebase 中的两个集合中获取数据

video - 用 flutter 捕捉视频

dart - 进程异常 : Process "C:\..\myapp\android\gradlew.bat" exited abnormally:

flutter - 在 flutter 中使用 try/catch 时 firebase_crashlytics 是否有效?

flutter - 如何在Flutter中从API选择索引并将其分别删除?

flutter - 读取 Assets 图像尺寸而不加载到内存中

C#平滑对象移动