MaybeWidget<T extends Object>.identifiable constructor
MaybeWidget<T extends Object>.identifiable (})
Identifiable constructor for the MaybeWidget class.
Creates a MaybeWidget with a key identifier. This ensures that the
widget will always have a different key than the one with a null value.
Typically used with animated parents.
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. Ifkeyis not provided, a null-check key will be calculated and used.
Example:
AnimatedSwitcher(
duration: const Duration(milliseconds: 800),
child: MaybeWidget.identifiable(
nullableValue,
(nonNullValue) => Text(nonNullValue.toString()),
),
),
Implementation
MaybeWidget.identifiable(
this.value,
this._builder, {
this.orElse = const SizedBox.shrink(),
this.buildWhen,
Key? key,
}) : super(key: key ?? ValueKey<bool>(value != null));