single<T> 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. @required 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.

Implementation

static Widget single<T>({
  @required BuildContext context,
  @required T Function(BuildContext context) valueBuilder,
  @required Map<T, Widget Function(BuildContext context)> caseBuilders,
  @required Widget Function(BuildContext context) fallbackBuilder,
}) {
  final T value = valueBuilder(context);
  if (caseBuilders[value] != null) {
    return caseBuilders[value](context);
  } else {
    return fallbackBuilder(context);
  }
}