build method

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

Builds the layout widget tree for the given content item.

This method is called by the content system to render the content item with the specified layout.

Implementation

@override
Widget build(BuildContext context, Document content) {
  final theme = Theme.of(context);
  final mode = (content.layout as DocumentDefaultLayout?)?.mode ??
      DocumentRenderMode.single;

  return Column(
    spacing: 4,
    children: [
      if (content.title != null)
        Text(content.title!, style: theme.textTheme.titleMedium),
      if (content.description != null) Text(content.description!),
      if (content.items != null && content.items!.isNotEmpty)
        Expanded(
            child: switch (mode) {
          DocumentRenderMode.single => VyuhContentBinding.content
              .buildContent(context, content.items!.first),
          DocumentRenderMode.list => CustomScrollView(
              cacheExtent: MediaQuery.sizeOf(context).height * 1.5,
              primary: true,
              slivers: [
                SliverList.builder(
                  itemBuilder: (context, index) => VyuhBinding
                      .instance.content
                      .buildContent(context, content.items![index]),
                  itemCount: content.items!.length,
                )
              ],
            )
        }),
    ],
  );
}