single<T> static method

Widget single<T>({
  1. required BuildContext context,
  2. required T valueBuilder(
    1. BuildContext context
    ),
  3. required Map<T, Widget Function(BuildContext context)> caseBuilders,
  4. Widget fallbackBuilder(
    1. BuildContext context
    )?,
})

A function which returns a single Widget

  • valueBuilder is a function which returns a value.
  • caseBuilders is a Map of value to Widget builders, when one of the keys matches the value returns by valueBuilder, the corresponding Widget builder will be used.
  • fallbackBuilder is a function which returns a Widget, it is used when none of the keys in caseBuildersmatches the value returns by valueBuilder. If fallbackBuilder is not provided, a Container() 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();
  }
}