搜索插件、代码仓与 APP 分类

插件详情v0.4.8

swipeable_page_route

向左滑动返回并欣赏精美变形的控件

AndroidiOSmacOSWindowsLinux
近 30 天下载
1.4万
喜欢数
320
Pub 分数
160

安装插件

flutter pub add swipeable_page_route

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

SwipeablePageRoute 是一个 Flutter 包,可在页面上启用直观的滑动返回导航手势,通过屏幕之间的平滑变形过渡提升用户体验。它扩展了标准的 PageRoute,提供可自定义的动画效果,并可无缝集成到现有的导航流程中。适用于注重流畅、交互式导航的应用程序,支持 Android、iOS、macOS、Windows 和 Linux 多个平台。该包轻量级,专为与 Flutter 的路由系统无缝协作而设计。

适合场景

  • 在移动应用中实现滑动返回导航
  • 通过动画过渡创建沉浸式用户体验
  • 通过手势驱动的导航增强应用互动性
  • 在各个平台上建立一致的导航模式
  • 为屏幕过渡添加视觉美化

主要特点

  • 流畅的滑动返回手势支持
  • 可自定义的过渡动画
  • 跨平台兼容性
  • 与现有路由的轻松集成
  • 导航期间的形态变换小部件过渡

适合对象

  • 寻求基于手势导航的开发者
  • 专注于用户参与度和用户体验的应用程序
  • Flutter 项目针对多个平台
  • 注重设计的应用程序,具有丰富的动画效果
  • 希望简化设置以实现高级导航的团队

使用建议

  • 可能需要额外的样式来实现复杂的过渡效果
  • 动画期间使用大量小部件的性能影响
  • 超出基本滑动行为的自定义功能有限
  • 不太适合简单的静态导航流程
  • 在嵌套导航场景中需要谨慎处理

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

🔙 Swipe to navigate back and admire beautifully morphing widgets.

swipeable_page_route demo

SwipeablePageRoute

SwipeablePageRoute is a specialized CupertinoPageRoute that allows your users to go back by swiping anywhere on the current page. Use it instead of MaterialPageRoute or CupertinoPageRoute:

Navigator.of(context).push(SwipeablePageRoute(
  builder: (BuildContext context) => MyPageContent(),
));

If your page contains horizontally scrollable content, you can limit SwipeablePageRoute to only react on drags from the start (left in LTR, right in RTL) screen edge — just like CupertinoPageRoute:

Navigator.of(context).push(SwipeablePageRoute(
  canOnlySwipeFromEdge: true,
  builder: (BuildContext context) => MyHorizontallyScrollablePageContent(),
));

You can get the SwipeablePageRoute wrapping your current page using context.getSwipeablePageRoute<T>().

To use swipeable pages with a PageTransitionsTheme, use SwipeablePageTransitionsBuilder.

⚠️ SwipeablePageTransitionsBuilder must be set for TargetPlatform.iOS. For all other platforms, you can decide whether you want to use it. This is because PageTransitionsTheme uses the builder for iOS whenever a pop gesture is in progress.

Usage with Go Router

To use swipeable pages with Flutter's Go Router, use SwipeablePage and the pageBuilder parameter in GoRoute instead of builder:

// Before, without swipeable pages:
GoRoute(
  builder: (context, state) => const MyScreen(),
  // ...
)

// After, with swipeable pages:
GoRoute(
  pageBuilder: (context, state) => SwipeablePage(
    builder: (context) => MyScreen(),
  ),
  // ...
)

MorphingAppBar & MorphingSliverAppBar

As you can see in the demo above, there's a beautiful animation happening to the app bar. That's a MorphingAppBar!

You can construct MorphingAppBar (corresponds to AppBar) and MorphingSliverAppBar (corresponds to SliverAppBar) just like the originals:

MorphingAppBar(
  backgroundColor: Colors.green,
  title: Text('My Page'),
  actions: [
    IconButton(
      key: ValueKey('play'),
      icon: Icon(Icons.play_arrow),
      onPressed: () {},
    ),
    IconButton(
      key: ValueKey('favorite'),
      icon: Icon(Icons.favorite),
      onPressed: () {},
    ),
    PopupMenuButton<void>(
      key: ValueKey('overflow'),
      itemBuilder: (context) => [
        PopupMenuItem<void>(child: Text('Overflow action 1')),
        PopupMenuItem<void>(child: Text('Overflow action 2')),
      ],
    ),
  ],
  bottom: TabBar(tabs: [
    Tab(text: 'Tab 1'),
    Tab(text: 'Tab 2'),
    Tab(text: 'Tab 3'),
  ]),
)

Both MorphingAppBars internally use Heros, so if you're not navigating directly inside a MaterialApp, you have to add a HeroController to your Navigator:

Navigator(
  observers: [HeroController()],
  onGenerateRoute: // ...
)

To animate additions, removals, and constants in your AppBars actions, we compare them using Widget.canUpdate(Widget old, Widget new). It compares Widgets based on their type and key, so it's recommended to give every action Widget a key (that you reuse across pages) for correct animations.

所属分类

依赖

依赖清单 3 项

源码仓库

使用此插件的项目

暂无相关数据。