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

套件詳情v1.0.5

layout

佈局透過使用統一的元素和間距,促進跨平台、跨環境和跨螢幕尺寸的一致性。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
2870
喜歡數
368
Pub 分數
150

安裝套件

flutter pub add layout

套件介紹

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

佈局套件透過提供一致的間距與可重複使用的佈局元件,促進跨平台與不同螢幕尺寸的UI設計一致性。它簡化了Flutter應用程式中的響應式設計,確保在Android、iOS、Web、macOS、Windows及Linux上的視覺和諧。透過標準化間距與結構,減少重複程式碼並提升可維護性。此套件非常適合希望在不犧牲彈性的情況下強制執行設計一致性的團隊。

適用情境

  • 跨平台應用程式開發
  • 響應式使用者介面設計
  • 保持設計一致性
  • 減少重複的佈局程式碼
  • 設計系統實施

主要特色

  • 統一間距指南
  • 可重用的佈局組件
  • 平台無關的設計
  • 簡化響應式佈局
  • 與現有 Flutter 項目整合

適合對象

  • 使用設計系統的團隊
  • 開發人員優先考慮一致性
  • 針對多個平台的專案
  • 需要可擴展佈局的應用程式
  • 以使用者介面為重點的 Flutter 開發者

使用建議

  • 需要遵守規定的間距規則
  • 可能需要為獨特設計進行客製化
  • 最佳搭配全面的設計系統
  • 僅限佈局結構,不包含樣式
  • 不是完整的使用者介面框架

原始 README

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

Layout

pub package

Following the Material Design Guidelines, Layout encourage consistency across platforms, environments, and screen sizes by using uniform elements and spacing.

Install

Follow the instructions to install it here

Getting started

This package aims to provide the tools to implement a responsive layout in an easy and consistent way.

If you want to learn more in detail about layout in Material Design I recommend you the official website.

Let's get started!

Everything starts with the Layout widget. Usually added at the top of your widget tree, but you can place it wherever you need it. It uses its widget constraints to calculate its breakpoint, columns, gutters, and margins.

  @override
  Widget build(BuildContext context) {
    return Layout(
      child: MaterialApp(
      ....
      ),
    );
  }

Breakpoints

A breakpoint is the range of predetermined screen sizes that have specific layout requirements. At a given breakpoint range, the layout adjusts to suit the screen size and orientation.

Each breakpoint range determines the number of columns, and recommended margins and gutters, for each display size.

By default the breakpoints are defined as:

  • xs: 0 – 599
  • sm: 600 – 1023
  • md: 1024 – 1439
  • lg: 1440 – 1919
  • xl: 1920 +
 @override
 Widget build(BuildContext context) {
   if(context.breakpoint > LayoutBreakpoint.md)
     return TabletView();
   else
     return MobileView();
 }

LayoutValues

A layout value is relative to the width of the screen. This way you can define responsive variable, reuse them and apply them when needed.

final double padding = context.layout.value(xs: 0.0, sm: 12.0, md: 24.0, lg: 32.0, xl: 48.0);

The most important layout values are the ones relative to the breakpoint. These are the most common and useful as you can define a value for different breakpoint sizes. If a breakpoint is not provided, its value will correspond to the first previous/smaller breakpoint.

final double padding = context.layout.value(
     xs: 0.0,  // sm value will be like xs 0.0
     md: 24.0, // lg value will be like md 24.0
     xl: 48.0
);

Layout values can be reused in different parts of the app with even different Layout widgets. For that they need to be created as

final displaySidebar = LayoutValue(xs: false, md: true);

final horizontalMargin = LayoutValue.builder((layout) {
    double margin = layout.width >= 500 ? 24.0 : 16.0;
    margin += 8.0 * layout.visualDensity.horizontal;
    return EdgeInsets.symmetric(horizontal: margin);
});

Then it can be used in any widget that has some Layout up in the tree as:

return Column(
  children: [
    Padding(
      padding: horizontalMargin.resolve(context),
      child:child,
    ),
    if(displaySidebar.resolve(context))
      SideBar(),
    ),
  ],
);

You can also create values relative to the layout width like.

final displaySidebar = LayoutValue.builder((layout) => layout.width > 600);

Margins

Margins are the space between content and the left and right edges of the screen.

  @override
  Widget build(BuildContext context) {
    return Margin(
      child: Text('This text'),
    );
  }

Margin widths are defined as fixed values at each breakpoint range. To better adapt to the screen, the margin width can change at different breakpoints. Wider margins are more appropriate for larger screens, as they create more whitespace around the perimeter of content.

By default the margin values are the ones from the Material Design Guidelines. 16dp for screens with a width less than 720dp and 24 for bigger screens. You can override these values in any moment by providing the margin param.

Fluid Margins

Some times you want to have a fixed width that stays the same across screen sizes.

  @override
  Widget build(BuildContext context) {
    return FluidMargin(
      child: Text('This text'),
    );
  }

Fluid margins are dynamically updated to keep a fixed size of its inner child. These fixed sizes are by default the ones from the Material Design Guidelines but can also easily customizable.

AdaptiveBuilder

A widget that allows easily to build responsive layouts

  @override
  Widget build(BuildContext context) {
    return AdaptiveBuilder(
      xs: (context) => LayoutWithBottomNavigationBar(),
      lg: (context) => LayoutWithTrailingNavigationBar(),
    );
  }

or for more complex cases

  @override
  Widget build(BuildContext context) {
    return  AdaptiveBuilder.builder(
      builder: (context, layout, child) {
        if (layout.breakpoint < LayoutBreakpoint.lg) {
          return LayoutWithBottomNavigationBar(child: child);
        } else {
          return LayoutWithTrailingNavigationBar(child: child);
        }
      },
      child: child,
    );
  }

Contributing

If you want to take the time to make this project better, you can open an new issue, or a pull request.

所屬分類

依賴

依賴清單 1 項

原始碼儲存庫

使用此套件的專案