send method

Future<DaemonResponse> send(
  1. String method, {
  2. Map<String, Object?> params = const {},
  3. Duration timeout = const Duration(seconds: 60),
})

Sends method with params, waiting for the matching response. Commands are gated behind app.start per the pinned protocol facts.

Implementation

Future<DaemonResponse> send(
  String method, {
  Map<String, Object?> params = const {},
  Duration timeout = const Duration(seconds: 60),
}) async {
  if (_exited) {
    throw DaemonException('cannot send $method — flutter attach exited');
  }
  if (!appStartReceived) {
    // Buffer until app.start rather than racing the daemon.
    await waitAppStart();
  }
  final id = _nextId++;
  final completer = _pending[id] = Completer<DaemonResponse>();
  _transport.writeLine(
    jsonEncode([
      {'id': id, 'method': method, 'params': params},
    ]),
  );
  final response = await completer.future.timeout(
    timeout,
    onTimeout: () {
      _pending.remove(id);
      throw DaemonException(
        'daemon did not answer $method within ${timeout.inSeconds}s',
      );
    },
  );
  return response;
}