搜索插件、代码仓与 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.

所属分类

源码仓库

使用此插件的项目

暂无相关数据。