如何在Flutter中实现类似iOS的平滑页面过渡动画?

时间:2019-05-07 16:07:22

标签: android ios dart flutter

我正在查看应用程序《万物的历史》,因为我正在学习编码Flutter应用程序。但是后来我注意到,应用程序中的页面过渡动画比我自己的应用程序(由Flutter制作)更流畅。您可以在下面看到比较:

My App

^您可以在我的应用程序中看到,当我做滑动手势并释放柄时,它会立即重置为0,而没有任何过渡。

The History of Everything

^您可以在《万物的历史》中看到,当我执行滑动手势并释放柄的方式时,它会平滑过渡到0。

我在GitHub(https://github.com/2d-inc/HistoryOfEverything)上检查了它们的源代码,并且使用MaterialPageRoute以相同的方式推动了这一路线。我已经使用释放模式在手机上构建了我的应用,因此它不应该与性能相关。

这是我推到一条新路线的方式:

Navigator.push(
  context,
  MaterialPageRoute(
    builder: (context) {
      return MessageScreen(conversation: _conversation);
    },
  ),
);

这是我的Flutter医生的输出:

[✓] Flutter (Channel stable, v1.2.1, on Mac OS X 10.14.4 18E226, locale en-HK)
[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[!] iOS toolchain - develop for iOS devices (Xcode 10.2.1)
    ✗ Verify that all connected devices have been paired with this computer in
      Xcode.
      If all devices have been paired, libimobiledevice and ideviceinstaller may
      require updating.
      To update with Brew, run:
        brew update
        brew uninstall --ignore-dependencies libimobiledevice
        brew uninstall --ignore-dependencies usbmuxd
        brew install --HEAD usbmuxd
        brew unlink usbmuxd
        brew link usbmuxd
        brew install --HEAD libimobiledevice
        brew install ideviceinstaller
[✓] Android Studio (version 3.4)
[✓] VS Code (version 1.33.1)
[!] Connected device
    ! No devices available

我在这里想念的有什么不同?

3 个答案:

答案 0 :(得分:0)

升级到Flutter 1.5后,它现在具有相同的页面过渡。

答案 1 :(得分:0)

您可以使用PageView并将页面及其内容封装为子页面。

答案 2 :(得分:0)

如果您想要像iOS这样的幻灯片过渡,请使用:

CupertinoPageRoute. 
Navigator.push(
    context, CupertinoPageRoute(builder: (context) => Screen2()))