registerExtensions method

void registerExtensions()

Registers the extensions. Call once, before runApp.

Implementation

void registerExtensions() {
  GuestExtensions.register('ext.flutterware.axes', (_, _) async {
    return developer.ServiceExtensionResponse.result(
      jsonEncode(describe().toJson()),
    );
  });
  GuestExtensions.register('ext.flutterware.setAxes', (_, args) async {
    // A service extension's arguments are strings, so the payload is JSON in
    // one of them rather than a map of typed values.
    var payload = jsonDecode(args['payload'] ?? '{}') as Map<String, dynamic>;
    var applied = apply({
      for (var shell in payload.entries)
        shell.key: (shell.value as Map).cast<String, Object?>(),
    });
    // Answered only once the shell has rebuilt on it, so a host that asks
    // what there is to show right afterwards is told about the build it
    // caused rather than the one it replaced. Bounded because a panel waits
    // on this: a guest that has stopped drawing should make it late, not
    // stuck.
    if (applied) {
      await WidgetsBinding.instance.endOfFrame.timeout(
        const Duration(seconds: 2),
        onTimeout: () {},
      );
    }
    return developer.ServiceExtensionResponse.result(
      jsonEncode(describe().toJson()),
    );
  });
}