build method

  1. @override
Widget build(
  1. BuildContext context,
  2. T content
)
override

Builds the layout for the content item. This transforms the content into a Flutter Widget.

Implementation

@override
Widget build(BuildContext context, T content) {
  return FutureBuilder(
      future: condition.execute(context),
      builder: (context, snapshot) {
        switch (snapshot.connectionState) {
          case ConnectionState.active || ConnectionState.done:
            if (snapshot.hasError) {
              return vyuh.widgetBuilder.errorView(
                context,
                error: snapshot.error,
                title:
                    'Failed to execute condition: ${condition.configuration?.schemaType}.',
              );
            }

            final value = snapshot.data ?? defaultCase;

            final caseItem =
                cases.firstWhereOrNull((element) => element.value == value);

            return caseItem?.item?.build(context, content) ??
                vyuh.widgetBuilder.errorView(context,
                    title:
                        'No LayoutConfiguration for content with schemaType: ${content.schemaType}.',
                    subtitle: 'Condition evaluated to: $value.');
          default:
            return vyuh.widgetBuilder.contentLoader(context);
        }
      });
}