list<T> method

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

A function which returns a List<Widget>

  • valueBuilder is a function which returns a value.
  • caseBuilders is a Map of value to List<Widget> builders, when one of the keys matches the value returns by valueBuilder, the corresponding List<Widget> builder will be used.
  • fallbackBuilder is a function which returns a List<Widget>, it is used when none of the keys in caseBuilders matches the value returns by valueBuilder.

Implementation

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