MaybeWidget<T extends Object> constructor
const
MaybeWidget<T extends Object> (})
Constructor for the MaybeWidget class.
valueis the value to check for null._builderis the builder function to call with a non-nullvalue.orElseis the widget to display ifvalueis null.buildWhenoptional predicate; if provided and returnstruethe builder runs, if it returnsfalseorElseis used. When omitted only the null-check is applied.keyis the key for the widget. Example:
MaybeWidget(
nullableText,
(text) => Text(text),
buildWhen: (text) => text.trim().isNotEmpty, // Only for non-empty text.
orElse: const Icon(Icons.text_decrease),
),
Implementation
const MaybeWidget(
this.value,
this._builder, {
this.orElse = const SizedBox.shrink(),
this.buildWhen,
super.key,
});