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

套件詳情v1.0.0

nested

一個幫助嵌套多個小部件而無需手動嵌套的 Flutter 小部件。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
526萬
喜歡數
350
Pub 分數
150

安裝套件

flutter pub add nested

套件介紹

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

嵌套套件是 Flutter 的一個實用工具,透過提供一種乾淨、宣告式的組合多個 widget 的方式,簡化了多重 widget 的巢狀結構。它讓開發者能以更直觀的方式鏈結 widget,提升複雜 UI 排版的可讀性與可維護性。非常適合減少 UI 程式碼中的重複程式碼,支援所有主要的 Flutter 平台,包含 Android、iOS、Web、macOS、Windows 與 Linux。

適用情境

  • 簡化複雜的組件層次結構
  • 減少嵌套小部件樣板程式碼
  • 提高UI程式碼可讀性
  • 簡化佈局組合
  • 建立可重用的組件鏈
  • 增強大型UI的可維護性

主要特色

  • 宣告式組件巢狀
  • 最小化樣板程式碼
  • 可鏈式組合的 Widget
  • 跨平台支援
  • 簡潔、易讀的語法
  • 無額外依賴

適合對象

  • 尋求更乾淨 UI 程式碼的開發者
  • 具有深度嵌套 Widget 的專案
  • 重視程式碼可維護性的團隊
  • UI 豐富的應用程式
  • Flutter 初學者學習組合
  • 經驗豐富的開發人員優化版面配置模式

使用建議

  • 僅限 widget 組合
  • 不是進階版佈局 widget 的取代品
  • 可能增加新使用者的學習曲線
  • 最佳搭配其他版面策略使用
  • 不取代狀態管理
  • 需要理解 Flutter 的 widget 樹

原始 README

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

pub package ci

A widget that simplifies the syntax for deeply nested widget trees.

Motivation

Widgets tend to get pretty nested rapidly. It's not rare to see:

MyWidget(
  child: AnotherWidget(
    child: Again(
      child: AndAgain(
        child: Leaf(),
      )
    )
  )
)

That's not very ideal.

There's where nested propose a solution. Using nested, it is possible to flatten the previous tree into:

Nested(
  children: [
    MyWidget(),
    AnotherWidget(),
    Again(),
    AndAgain(),
  ],
  child: Leaf(),
),

That's a lot more readable!

Usage

Nested relies on a new kind of widget: SingleChildWidget, which has two concrete implementation:

These are SingleChildWidget variants of the original Stateless/StatefulWidget.

The difference between a widget and its single-child variant is that they have a custom build method that takes an extra parameter.

As such, a StatelessWidget would be:

class MyWidget extends StatelessWidget {
  MyWidget({Key key, this.child}): super(key: key);

  final Widget child;

  @override
  Widget build(BuildContext context) {
    return SomethingWidget(child: child);
  }
}

Whereas a SingleChildStatelessWidget would be:

class MyWidget extends SingleChildStatelessWidget {
  MyWidget({Key key, Widget child}): super(key: key, child: child);

  @override
  Widget buildWithChild(BuildContext context, Widget child) {
    return SomethingWidget(child: child);
  }
}

This allows our new MyWidget to be used both with:

MyWidget(
  child: AnotherWidget(),
)

and to be placed inside children of [Nested] like so:

Nested(
  children: [
    MyWidget(),
    ...
  ],
  child: AnotherWidget(),
)

所屬分類

原始碼儲存庫

使用此套件的專案