single<T> static method
Widget
single<T>({
- required BuildContext context,
- required T valueBuilder(
- BuildContext context
- required Map<
T, Widget Function(BuildContext context)> caseBuilders, - Widget fallbackBuilder(
- BuildContext context
A function which returns a single Widget
valueBuilder
is a function which returns a value.caseBuilders
is aMap
of value toWidget
builders, when one of the keys matches the value returns byvalueBuilder
, the correspondingWidget
builder will be used.fallbackBuilder
is a function which returns aWidget
, it is used when none of the keys incaseBuilders
matches the value returns byvalueBuilder
. IffallbackBuilder
is not provided, aContainer()
will be returned.
Implementation
static Widget single<T>({
required BuildContext context,
required T Function(BuildContext context) valueBuilder,
required Map<T, Widget Function(BuildContext context)> caseBuilders,
Widget Function(BuildContext context)? fallbackBuilder,
}) {
final T value = valueBuilder(context);
if (caseBuilders[value] != null) {
return caseBuilders[value]!(context);
} else {
return fallbackBuilder?.call(context) ?? Container();
}
}