Search packages, repositories and app categories

Package detailsv1.1.1

nil

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

AndroidiOSWebmacOSWindowsLinux
30-day downloads
9.5K
Likes
324
Pub points
140

Install package

flutter pub add nil

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

The nil package provides a minimal, performance-optimized widget that renders nothing when included in the widget tree. It's designed for scenarios where you need a placeholder or conditional widget that doesn't contribute to layout or rendering overhead. Unlike SizedBox.shrink() or Container(), nil has zero impact on the widget tree’s performance and is ideal for dynamic UI logic where visibility conditions are handled externally. It's lightweight and safe to use in complex or frequently updated UIs.

Use cases

  • Conditional rendering with no visual output
  • Replacing empty containers in dynamic layouts
  • Optimizing performance in large widget trees
  • Simplifying null checks in widget composition
  • Avoiding unnecessary layout calculations

Key features

  • Zero rendering cost
  • No layout impact
  • Minimal memory footprint
  • Simple API
  • Safe for frequent updates

Suitable for

  • Developers optimizing UI performance
  • Builders of dynamic or conditional UIs
  • Teams prioritizing minimal overhead
  • Apps with complex or nested widget trees
  • Those seeking a clean alternative to empty widgets

Considerations

  • Not suitable for visible content
  • Does not support child widgets
  • Only useful when intentionally rendering nothing
  • Not needed if using built-in null-safe constructs
  • Best used in conjunction with conditional logic

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

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.

Categories

Source repository

Projects using this package