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

パッケージ詳細v1.1.1

nil

表示するものが何も無いときにウィジェットツリーに追加するためのシンプルなウィジェットで、パフォーマンスへの影響が最小限です。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
9530
いいね数
324
Pub ポイント
140

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

flutter pub add nil

パッケージ概要

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

nil パッケージは、ウィジェットツリーに含まれたときに何もレンダリングしない、最小限でパフォーマンス最適化されたウィジェットを提供します。レイアウトやレンダリングのオーバーヘッドに寄与しないプレースホルダーまたは条件付きウィジェットが必要な状況に設計されています。SizedBox.shrink() や Container() とは異なり、nil はウィジェットツリーのパフォーマンスにまったく影響を与えず、可視性条件を外部で処理する動的な UI ロジックに最適です。軽量であり、複雑または頻繁に更新される UI でも安全に使用できます。

用途

  • 視覚的出力のない条件付きレンダリング
  • 動的レイアウト内の空のコンテナを置き換える
  • 大規模なウィジェットツリーでのパフォーマンス最適化
  • ウィジェット構成におけるnullチェックの簡素化
  • 不要なレイアウト計算を避ける

主な機能

  • レンダリングコストゼロ
  • レイアウトへの影響なし
  • 最小限のメモリ使用量
  • シンプルな API
  • 頻繁な更新に安全

適している対象

  • 開発者がUIパフォーマンスを最適化しています
  • 動的または条件付きUIの構築者
  • 最小限のオーバーヘッドを重視するチーム
  • 複雑またはネストされたウィジェットツリーを持つアプリ
  • 空のウィジェットのクリーンな代替品を探している人

注意事項

  • 表示されるコンテンツには適していません
  • 子ウィジェットをサポートしていません
  • 意図的に何もレンダリングしないときにのみ有用
  • 組み込みのnull安全な構文を使用している場合は不要です
  • 条件付きロジックと併用するのが最適です

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

Build Pub Codecov

nil

A simple widget to add in the widget tree when you want to show nothing, with minimal impact on performance.

Why?

Sometimes, according to a condition, we want to display nothing. Usually when we can't return null, we would return something like const SizedBox() for example.

This is good, but it has some performance impacts since SizedBox creates a RenderObject. The RenderObject lives in the render tree and some computations are performed on it, even if it paints nothing on the screen.

We can do better, we can have a widget which does not create a RenderObject, while being still valid. The Nil widget is the minimal implementation for this use case. It only creates an Element and does nothing while it's building. Because the optimal way to use it, is to call const Nil(), it also comes with a nil constant that you can use everywhere (which is a const Nil()).

Usage

import 'package:nil/nil.dart';

return Builder(
  builder: (_) {
    if (condition) {
      return const MyWidget();
    } else {
      return nil;
    }
  },
);

Warning

This widget is not intended to be used in widgets accepting multiple children (e.g. Rows, Columns, etc.). The best option is to not add a widget in the list if you don't want it to be displayed. Moreover using a Nil widget in such a case, can have unexpected results.

Sponsoring

I'm working on my packages on my free-time, but I don't have as much time as I would. If this package or any other package I created is helping you, please consider to sponsor me so that I can take time to read the issues, fix bugs, merge pull requests and add features to these packages.

Contributions

Feel free to contribute to this project.

If you find a bug or want a feature, but don't know how to fix/implement it, please fill an issue.
If you fixed a bug or implemented a feature, please send a pull request.

カテゴリー

ソースリポジトリ

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