Description
DocumentConnectionScope
is a builder widget that manages the lifecycle of a document connection in a MeshAgent application.
- Parameters:
path
(string): Path to the document.
room
(RoomClient): Instance of RoomClient
to manage the connection.
builder
(function): A callback function that takes the current context, the loaded MeshDocument
, and any error that occurred during loading.
- Returns:
Widget
: A widget that builds based on the state of the document connection.
Example
import 'package:flutter/widgets.dart';
import 'package:meshagent/meshagent.dart';
import 'package:meshagent_flutter/meshagent_flutter.dart';
class SampleWidget extends StatelessWidget {
const SampleWidget({
super.key,
required this.room,
required this.path,
});
final RoomClient room;
final String path;
@override
Widget build(BuildContext context) {
return DocumentConnectionScope(
path: path,
room: room, // instance of MeshRoom
builder: (context, document, error) {
if (error != null) {
// Handle the error
return Text('Error: $error');
}
if (document == null) {
// Document is still loading
return Text('Loading...');
}
return Text('Document loaded: ${document.id}');
});
}
}