MaybeWidget<T extends Object>.offstage constructor

const MaybeWidget<T extends Object>.offstage(
  1. T? value,
  2. Widget _builder(
    1. T
    ), {
  3. Widget orElse = const Offstage(),
  4. bool buildWhen(
    1. T
    )?,
  5. Key? key,
})

Creates a MaybeWidget that uses Offstage as the default orElse widget.

This constructor is useful when you want to preserve the layout space even when the value is null, but make the widget invisible.

  • value is the value to check for null.
  • _builder is the builder function to call with a non-null value.
  • orElse defaults to Offstage when value is null.
  • buildWhen optional predicate; if provided and returns true the builder runs, if it returns false orElse (the Offstage widget unless overridden) is used. When omitted only the null-check is applied.
  • key is the key for the widget.

Example:

MaybeWidget.offstage(
  nullableValue,
  (value) => Text(value.toString()),
)

Implementation

const MaybeWidget.offstage(
  this.value,
  this._builder, {
  this.orElse = const Offstage(),
  this.buildWhen,
  super.key,
});