搜尋套件、儲存庫與 APP 分類

master_detail_scaffold 封面
套件詳情v2.0.0

master_detail_scaffold

用於實現響應式主細節骨架元件的套件

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
19
喜歡數
21
Pub 分數
150

安裝套件

flutter pub add master_detail_scaffold

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個 Flutter 套件,提供響應式主-細節骨架小工具,可在不同螢幕尺寸之間實現清單(主)與詳細檢視(細節)的無縫導航。它會根據裝置寬度自動調整版面,於行動裝置、平板電腦與網頁平台提供一致的使用者體驗。非常適合需要層級內容顯示的資料密集型應用,例如儀表板或管理介面。該小工具透過內建的響應式邏輯與可自訂的回呼函數簡化實作。

適用情境

  • 建構響應式管理儀表板
  • 建立資料探索介面
  • 在多個平台上實現列表-詳情導航
  • 為平板電腦和桌面設備設計自適應佈局
  • 開發內容管理系統

主要特色

  • 根據螢幕尺寸自動版面適應
  • 支援所有主要的 Flutter 平台
  • 可自訂的主控和細節小部件
  • 內建的移動和桌面端響應式行為
  • 透過單一元件實現簡單整合

適合對象

  • 開發跨平台 UI 的開發者
  • 需要響應式列表-詳情模式的團隊
  • 同時面向行動和桌面用戶的App
  • 需要最少樣板代碼的主細節資訊佈局項目

使用建議

  • 可能需要額外的樣式來處理複雜佈局
  • 對非標準轉換的自訂有限
  • 最適合簡單的列表-詳情流程
  • 不太適合高度動態或嵌套的導航結構

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

master_detail_scaffold

pub package Build Status

A Flutter package that contains widgets that help implement a responsive master-detail layout. The widget is based on the material design scaffold and was based on exploring responsive layouts as covered in this article. As such, it may not suitable for all scenarios (e.g. nested/multiple master-detail layouts) as it has been shared in case there are other members of the community who may find it useful. Go here to see the example running on the web.

NOTE: this uses the imperative Navigator (1.0) APIs. There are currently no plans to migrate this to Navigator 2.0 so those that need Navigator 2.0 should look at forking this project

Getting started

The package exposes a MasterDetailScaffold widget that is built based on Flutter's Scaffold widget. Therefore, you can expect the majority of the properties you're familiar to exist and can be use it in a similar way you would normally do with a Scaffold widget. Create a class and use the MasterDetailScaffold widget within your build method

MasterDetailScaffold(
    onDetailsPaneRouteChanged:
        (String route, Map<String, String> parameters) {
    setState(() {
        if (route == RouteNames.itemDetails) {
        _selectedItem = content.items.firstWhere(
            (item) => item.id == parameters['id'],
            orElse: null);
        return;
        }
        _selectedItem = null;
    });
    },
    twoPanesWidthBreakpoint: 600,
    initialRoute: RouteNames.home,
    detailsRoute: RouteNames.itemDetails,
    initialAppBar: AppBar(
    title: Text('Master-detail Flow Demo'),
    ),
    masterPaneWidth: 400,
    masterPaneBuilder: (BuildContext context) => ItemsList(
    selectedItem: _selectedItem,
    ),
    detailsPaneBuilder: (BuildContext context) =>
        ItemDetails(item: _selectedItem),
    detailsAppBar: AppBar(
    // the [Builder] widget is needed to ensure that the widget for displaying the title gets rebuilt based on the selected item.
    // Without the [Builder] widget, the title is set to the value that was originally passed through
    title: Builder(
        builder: (context) => Text(_selectedItem.title),
    ),
    ),
    floatingActionButton: Visibility(
    visible: _selectedItem != null,
    child: Builder(
        builder: (context) => FloatingActionButton(
        child: Icon(Icons.reply),
        onPressed: () {
            ScaffoldMessenger.of(context).showSnackBar(
            SnackBar(
                content: Text('Replying to ${_selectedItem.title}'),
            ),
            );
        },
        ),
    ),
    ),
);

The key parts are

  • twoPanesWidthBreakpoint: the width breakpoint for showing both the master and details pane together. The back button is hidden whe both panes are visible
  • initialRoute: the name of the route use when no details are shown in the details pane
  • detailsRoute: the name of the route to use when details are shown in the details pane
  • masterPaneWidth: the width of the master pane. Applicable when both the master and details pane are shown
  • masterPaneBuilder: determines what to show in the master pane. This is typically a list of items and is left to developers to implement what they should render here
  • detailsPaneBuilder: determines what to show in the details pane. When both the master and details pane are shown, it is assumed to take the remaining of width of the screen
  • onDetailsPaneRouteChanged: the callback trigger when the route in the details pane changes. Use this to find out get the route/path and query string parameters so you can display the appropriate content

To trigger navigation in the details pane, you can retrieve the navigator associated with the details pane by calling MasterDetailScaffold.of(context).detailsPaneNavigator. Normally, this wouldn't be needed and you would only need to call Navigator.of(context) but this doesn't appear to get the navigator associated with the details pane. URI-based navigation is expected via named routes. By default the page transition applied is the same as the MaterialPageRoute, though when both panes are shown no animation is used when the details change. Should you want to use a different transition style, this can be specified using the pageRouteBuilder property.

Note that I've found that entering a URL that should go to a specific details page doesn't work. This is likely due to the fact that Flutter's web support for web development isn't stable yet. Should you find a solution for this, please submit a pull request.

Should you want to see this running, a complete example can be found in the GitHub repository.

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。