パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v1.0.0

nested

複数のウィジェットを手動でネストすることなく、ネストするのを助けるFlutterウィジェットです。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
526万
いいね数
350
Pub ポイント
150

パッケージをインストール

flutter pub add nested

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

ネストされたパッケージは、Flutterのユーティリティで、手動でネストされたウィジェット構造を書くことなく、複数のウィジェットをきれいな宣言型の方法で組み合わせることを可能にします。複雑なUIレイアウトにおける読みやすさと保守性を高めるため、開発者がより直感的な方法でウィジェットをチェーンできます。UIコードのボイラープレートを削減するのに理想的であり、Android、iOS、Web、macOS、Windows、Linuxを含むすべての主要なFlutterプラットフォームをサポートしています。

用途

  • 複雑なウィジェット階層の簡素化
  • ネストされたウィジェットのボイラープレートを減らす
  • UIコードの可読性を向上させる
  • レイアウトの構成を最適化する
  • 再利用可能なウィジェットチェーンの作成
  • 大規模なUIの保守性を高める

主な機能

  • 宣言的ウィジェットのネスト
  • 最小限のボイラープレート
  • チェイン可能なウィジェットの組み合わせ
  • クロスプラットフォーム対応
  • 洗練された、読みやすい構文
  • 追加の依存関係なし

適している対象

  • より洗練されたUIコードを求める開発者
  • 深くネストされた Widget を持つプロジェクト
  • コードの保守性を重視するチーム
  • UI重視のアプリケーション
  • Flutter初心者がコンポジションを学ぶ
  • 経験豊富な開発者がレイアウトパターンを最適化する

注意事項

  • ウィジェットの組み合わせのみに限定
  • 高度なレイアウトウィジェットの代替品ではありません
  • 新規ユーザーの習得難易度が高まる可能性があります
  • 他のレイアウト戦略と併用するのが最適です
  • 状態管理を置き換えるものではない
  • Flutter のウィジェットツリーの理解が必要です

元の 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(),
)

カテゴリー

ソースリポジトリ

このパッケージを使用しているプロジェクト