pageLoaderFor method

PageLoader pageLoaderFor(
  1. Client client, {
  2. Map<String, dynamic> transform(
    1. Map<String, dynamic>
    )?,
})

FR-APP-006

transform is applied to every page before it reaches the runtime. The server-open path passes the served bundle's bundle:// resolver so a page loaded later resolves its assets exactly as the entry document did — mcp_ui_dsl §6.12.7 requires one placement per host, not one per document, and a page that resolved on the first frame and not on the second would be the worst version of that.

Implementation

PageLoader pageLoaderFor(
  Client client, {
  Map<String, dynamic> Function(Map<String, dynamic>)? transform,
}) {
  return (String uri) async {
    _logger.debug('Loading page', {'uri': uri});
    final page = await client.readResource(uri);
    if (page.contents.isEmpty) return <String, dynamic>{};
    final text = page.contents.first.text ?? '{}';
    final decoded = jsonDecode(text);
    final map = decoded is Map<String, dynamic>
        ? decoded
        : <String, dynamic>{};
    return transform == null ? map : transform(map);
  };
}