DocumentBuilder<T> class final

A widget that builds UI based on document data fetched from a content provider.

This widget is responsible for fetching document data from a content provider and building UI based on that data. It supports both static and live document loading, and can be configured to allow refreshing the document.

Example usage:

// Using the factory method to fetch by query
DocumentBuilder.fromQuery<BlogPost>(
  query: '*[_type == "blog.post" && slug.current == $slug][0]',
  fromJson: BlogPost.fromJson,
  allowRefresh: true,
  isLive: true,
  buildContent: (context, post) => BlogPostView(post: post),
)

// Using the factory method to fetch by ID
DocumentBuilder.fromId<BlogPost>(
  id: 'blog-post-123',
  fromJson: BlogPost.fromJson,
  allowRefresh: true,
  buildContent: (context, post) => BlogPostView(post: post),
)

// Using a custom future
DocumentBuilder<BlogPost>(
  fetchDocument: () => myCustomFuture,
  allowRefresh: true,
  buildContent: (context, post) => BlogPostView(post: post),
)
Inheritance

Constructors

DocumentBuilder.new({Key? key, required Future<T?> fetchDocument(), Stream<T?>? liveDocument, required Widget buildContent(BuildContext context, T document), bool allowRefresh = true, bool isLive = false, Future<T?> initDocument(BuildContext context, T document)?})
Creates a DocumentBuilder with a custom document fetching function.
const

Properties

allowRefresh bool
Whether to allow refreshing the document.
final
buildContent Widget Function(BuildContext context, T document)
A function that builds the UI for the document.
final
fetchDocument Future<T?> Function()
A function that returns a future of the document.
final
hashCode int
The hash code for this object.
no setterinherited
initDocument Future<T?> Function(BuildContext context, T document)?
Optional custom initialization function for the document. This allows for document-specific initialization logic.
final
isLive bool
Whether to use live document updates.
final
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
liveDocument Stream<T?>?
A stream of document data for live updates.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

build(BuildContext context) Widget
Describes the part of the user interface represented by this widget.
override
createElement() StatelessElement
Creates a StatelessElement to manage this widget's location in the tree.
inherited
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
inherited
toStringShort() String
A short, textual description of this widget.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

fromId<T>({Key? key, required String id, required FromJsonConverter<T> fromJson, required Widget buildContent(BuildContext, T), bool includeDrafts = false, bool allowRefresh = true, bool isLive = false, Future<T?> initDocument(BuildContext, T?)?}) DocumentBuilder<T>
Creates a DocumentBuilder that fetches a document by ID.
fromQuery<T>({Key? key, required String query, Map<String, String>? queryParams, required FromJsonConverter<T> fromJson, required Widget buildContent(BuildContext, T), bool includeDrafts = false, bool allowRefresh = true, bool isLive = false, Future<T?> initDocument(BuildContext, T?)?}) DocumentBuilder<T>
Creates a DocumentBuilder that fetches a document by query.
fromRoute({Key? key, Uri? url, String? routeId, required Widget buildContent(BuildContext, RouteBase), bool includeDrafts = false, bool allowRefresh = true, bool isLive = false}) DocumentBuilder<RouteBase>
Creates a DocumentBuilder that fetches a route by path or ID.