Skip to main content

Description

DocumentConnectionScope is a builder widget that manages opening and keeping a document connection alive (with simple retry and close-on-dispose).
  • path: Document path to open (created if missing).
  • room: Connected RoomClient.
  • builder: (BuildContext, MeshDocument?, Object?) called with the current document (or null while loading) and any error.
  • Returns: Widget that rebuilds as the document loads/retries.

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}');
      });
  }
}