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

Overview

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.

You might also like...

Show custom in-app notification with any Widgets in flutter

Show custom in-app notification with any Widgets in flutter

notify_inapp show custom in-app notification with any Widgets. Getting Started Add this to your package's pubspec.yaml file: dependencies: notify_in

Aug 19, 2022

A Flutter plugin which makes it straightforward to show the native equivalent of a CupertinoAlertDialog or CupertinoActionSheet dialog

A Flutter plugin which makes it straightforward to show the native equivalent of a CupertinoAlertDialog or CupertinoActionSheet dialog

A Flutter plugin which makes it straightforward to show the native equivalent of a CupertinoAlertDialog or CupertinoActionSheet dialog

Dec 9, 2022

A Flutter package to show beautiful animated snackbars directly using overlay

A Flutter package to show beautiful animated snackbars directly using overlay

Easily show beautiful snack bars directly using overlays. Create custom snack bars and show them with awesome animations.

Dec 27, 2022

A Flutter library to add bubble tab indicator to TabBar

A Flutter library to add bubble tab indicator to TabBar

Bubble Tab Indicator A Flutter library to add bubble tab indicator to TabBar. Getting Started Add package from github by adding the following to your

Nov 23, 2022

A Flutter library to add the Common effect (line, bubble, dot ...) of tab indicator.

A Flutter library to add the Common effect (line, bubble, dot ...) of tab indicator.

flutter_tab_indicator A Flutter library to add the Common effect (line, bubble, dot ...) of tab indicator. Showcases Installation Showcases Showcases

Jun 19, 2022

Flutter Package: When your desired layout or animation is too complex for Columns and Rows, this widget lets you position/size/rotate/transform its child in complex ways.

Flutter Package: When your desired layout or animation is too complex for Columns and Rows, this widget lets you position/size/rotate/transform its child in complex ways.

align_positioned Widgets in this package: AlignPositioned AnimatedAlignPositioned AnimChain Why are these widgets an indispensable tool? When your des

Dec 12, 2022

The flutter_otp_text_field package for flutter is a TextField widget that allows you to display different style pin.

The flutter_otp_text_field package for flutter is a TextField widget that allows you to display different style pin.

flutter_otp_text_field flutter_otp_text_field The flutter_otp_text_field package for flutter is a TextField widget that allows you to display differen

Nov 8, 2022

Flutter package which helps you to implement Ticket Widget in your app.

Flutter package which helps you to implement Ticket Widget in your app.

✨ Ticket Widget Flutter package which helps you to implement Ticket Widget in your app. The source code is 100% Dart, and it is an updated null safe v

Dec 30, 2022

An alternative to Overlay which allows you to easily render and hit test a widget outside its parent bounds

An alternative to Overlay which allows you to easily render and hit test a widget outside its parent bounds. Based on the original idea by @shrouxm he

Dec 31, 2022
Comments
  • Nil under a MultiChildRenderObjectElement

    Nil under a MultiChildRenderObjectElement

    You are using Nil under a MultiChildRenderObjectElement. This suggests a possibility that the Nil is not needed or is being used improperly. Make sure it can't be replaced with an inline conditional or omission of the target widget from a list.

    opened by mario202k 2
  • Question - Can nil be used with AnimatedSwitcher?

    Question - Can nil be used with AnimatedSwitcher?

    Sometimes there is a need to give an AnimatedSwitcher an empty space (like SizedBox). Is nil compatible with this? AnimatedSwitcher is using a Stack to do the switch, and because you wrote that nil can't be used inside a widget that contains children I'm asking this.

    Thanks.

    opened by naamapps 0
Owner
Romain Rastel
Flutter Developer
Romain Rastel
A high performance Flutter Widget to render Bottts svg avatars on android/ios devices.

Flutter Avatars - Bottts A high performance Flutter Widget to render Bottts svg avatars on android/ios devices. (pub.dev) It's faster than other class

Abhijat Saxena 11 Dec 19, 2021
Responsive Widgets Prefix allows you to add the "Responsive" prefix to any widget that needs scaling or font size increases

Responsive Widgets Prefix allows you to add the Responsive prefix to any widget that needs scaling or font size increases (for varying device screen sizes).

The Mobile Applications Community 2 Apr 18, 2022
A sliding up panel widget which can be used to show or hide content, beautiful and simple.

flutter_sliding_up_panel A sliding up panel widget which can be used to show or hide content, beautiful and simple. demo Getting Started dependencies:

null 25 Dec 12, 2022
Animated Search Bar package lets you add a beautiful search bar to your Flutter app.

Animated Search Bar Animated Search Bar package lets you add a beautiful search bar to your Flutter app. Installation Add the latest version of packag

Mohammad Saleh 5 Aug 7, 2022
Donation/Support buttons to allow you to add your favorite support buttons like: Paypal, Ko-fi or Patreon and more.

flutter_donation_buttons Donation/Support buttons to allow you to add your favorite support buttons like: Paypal, Ko-fi or Patreon and more. Getting S

null 6 Dec 10, 2022
Flutter widget to show text in popup or overlay container

flutter_show_more_text_popup Flutter widget to show text in popup or overlay container Installation Add this to your package's pubspec.yaml file depen

Sanjay Sharma 44 Jul 5, 2022
A Flutter widget to show a text form field to display a date or clock dialog

A Flutter widget to show a text form field to display a date or clock dialog. This widget extend TextField and has a similar behavior as TextFormField.

m3uzz Soluções em TI 82 Jan 6, 2023
Main focus is to show dynamic operation not supported in Stateless Widget of Flutter

A new Flutter project. It will count the number of donut(Though increment doesnot take place Stateless Widget). Main focus is to show dynamic operation not supported in Stateless Widget of Flutter.

Avinandan Bose 2 Sep 9, 2022
Flutter Number Picker is a custom widget designed for choosing an integer or decimal number by using add and minus buttons

Flutter Number Picker is a custom widget designed for choosing an integer or decimal number by using add and minus buttons. Getting Started Head to /p

Vũ Phương 2 Jul 4, 2022
Add decoration capabilities for the Icon widget with shadows, borders, gradients.

icon_decoration Add decoration capabilities for the Icon widget with shadows, borders, gradients. This new DecoratedIcon widget overlap itself with th

Guillaume Roux 23 Oct 7, 2022