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
valueBuilderis a function which returns a value.caseBuildersis aMapof value toWidgetbuilders, when one of the keys matches the value returns byvalueBuilder, the correspondingWidgetbuilder will be used.fallbackBuilderis a function which returns aWidget, it is used when none of the keys incaseBuildersmatches the value returns byvalueBuilder. IffallbackBuilderis 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();
}
}