vyuh_content_widget
Embed framework content in an existing Flutter app using VyuhContentBinding and VyuhContentWidget. Initialize the binding before Flutter runApp, await widgetReady for service access, and use your host app for navigation ownership.
How the pieces fit together
Choose a declaration
Document · DocumentBuilder · DocumentDefaultLayout · DocumentListBuilder · DocumentRenderMode · VyuhContentBinding · VyuhContentWidget
Document
A document is a content item that represents a structured document. It contains a set of fields like title, description, and content that are defined by the document's schema. The document is used to display structured content in the app.
final class Document extends ContentItemDirectly declared public members:
static const dynamic schemaName;static final dynamic typeDescriptor;The default type descriptor for documents. Used for deserialization.
static final dynamic descriptor;Used for extending the layouts of documents
static final dynamic contentBuilder;The default content builder for documents, which assembles all the descriptors and constructs the final document representation.
final String? title;The title of the document. This is used to display the title of the document in the app. The title is typically displayed in the app's top navigation bar or in the document's header.
final String? description;The description of the document. This is an optional field and is used to provide additional information about the document.
final List<ContentItem>? items;The content of the document. This is the actual content of the document. The content is typically displayed in the document's body.
static List<ContentItem>? itemsList(dynamic json);Document({this.title, this.description, this.items, super.layout, super.modifiers});Creates a new document with the given title, description, and content.
factory Document.fromJson(Map<String, dynamic> json);DocumentBuilder
A widget that renders a Document from the CMS.
typedef DocumentBuilder<T extends ContentItem> = Widget Function(BuildContext, T);DocumentDefaultLayout
The default layout for documents. It shows a column view of title, description, and content.
final class DocumentDefaultLayout extends LayoutConfiguration<Document>Directly declared public members:
static const dynamic schemaName;static final dynamic typeDescriptor;final DocumentRenderMode mode;DocumentDefaultLayout({this.mode = DocumentRenderMode.single});factory DocumentDefaultLayout.fromJson(Map<String, dynamic> json);Widget build(BuildContext context, Document content);DocumentListBuilder
A widget that renders a list of Documents from the CMS.
typedef DocumentListBuilder<T extends ContentItem> = Widget Function(BuildContext, List<T>);DocumentRenderMode
Public declaration in this package.
enum DocumentRenderModeVyuhContentBinding
The binding layer for the VyuhContentWidget. It provides access to various plugins, including the content plugin. You can also customize the default widget builders for showing loaders and errors.
final class VyuhContentBindingDirectly declared public members:
static void init({required PluginDescriptor plugins, List<ContentExtensionDescriptor>? descriptors, PlatformWidgetBuilder? widgetBuilder, Future<void> Function(VyuhBinding)? onReady});Initializes the binding layer for the VyuhContentWidget. This is a required call before using the widget. It takes in a PluginDescriptor and optional parameters for customizing the widget builders. The descriptors are used for extending the default content types and content builders. You can also be notified once the binding layer is completely ready by providing an onReady callback.
static ContentPlugin get content;The default content plugin used by the VyuhContentWidget.
static PlatformWidgetBuilder get widgetBuilder;The default widget builder used by the VyuhContentWidget.
static final dynamic standardDescriptors;The default descriptors used by the VyuhContentWidget. It includes the Document type and several content-types from the vyuh_feature_system package.
static Future<void> dispose();VyuhContentWidget
A versatile content widget that handles both single and list content items. It interacts with the ContentPlugin (either directly or via VyuhBinding) to fetch content from the CMS.
class VyuhContentWidget<T extends ContentItem> extends StatefulWidgetDirectly declared public members:
final String query;The query to fetch content from the CMS.
final Map<String, String>? queryParams;The query parameters to pass to the CMS.
final FromJsonConverter<T> fromJson;The converter to use when converting the raw JSON data from the CMS into a ContentItem.
final DocumentBuilder<T>? builder;The builder to use when the widget is displaying a single content item.
final DocumentListBuilder<T>? listBuilder;The builder to use when the widget is displaying a list of content items.
const VyuhContentWidget({super.key, this.query = _defaultSanityQuery, required this.fromJson, this.queryParams, this.builder, this.listBuilder});Creates a VyuhContentWidget with the given parameters.
factory VyuhContentWidget.fromDocument({Key? key, required String identifier, String? query, Map<String, String>? queryParams, Widget Function(BuildContext, Document)? builder});Creates a VyuhContentWidget that loads a single Document from the CMS. If a query is not provided, it will default to a Sanity GROQ query. This assumes that you have setup a SanityContentProvider for the ContentPlugin.
State<VyuhContentWidget<T>> createState();