build method

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

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

Implementation

@override
Widget build(BuildContext context, DocumentSectionView content) {
  if (content.configuration == null) {
    return vyuh.widgetBuilder.errorView(
      context,
      title: 'Cannot render section',
      error: 'No configuration found for this document section',
    );
  }

  final docWidgetState = DocumentViewBuilderState.of(context);

  return Observer(builder: (context) {
    final snapshot = docWidgetState.document<DocumentItem>();

    if (snapshot.status == FutureStatus.pending) {
      return vyuh.widgetBuilder.contentLoader(context);
    }

    if (snapshot.result == FutureStatus.rejected) {
      return vyuh.widgetBuilder.errorView(
        context,
        title: 'No document found',
        error: snapshot.error,
      );
    }

    return content.configuration!.build(context, snapshot.result!);
  });
}