搜尋套件、儲存庫與 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 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。