startDartDevelopmentService static method

Future<DartDevelopmentService> startDartDevelopmentService(
  1. Uri remoteVmServiceUri, {
  2. Uri? serviceUri,
  3. bool enableAuthCodes = true,
  4. bool ipv6 = false,
  5. bool enableServicePortFallback = false,
  6. List<String> cachedUserTags = const [],
  7. DevToolsConfiguration? devToolsConfiguration,
  8. bool logRequests = false,
  9. UriConverter? uriConverter,
})

Creates a DartDevelopmentService instance which will communicate with a VM service. Requires the target VM service to have no other connected clients.

remoteVmServiceUri is the address of the VM service that this development service will communicate with.

If provided, serviceUri will determine the address and port of the spawned Dart Development Service. The format of serviceUri must be consistent with the protocol determined by ipv6.

enableAuthCodes controls whether or not an authentication code must be provided by clients when communicating with this instance of DartDevelopmentService. Authentication codes take the form of a base64 encoded string provided as the first element of the DDS path and is meant to make it more difficult for unintended clients to connect to this service. Authentication codes are enabled by default.

ipv6 controls whether or not DDS is served via IPv6. IPv4 is enabled by default.

If enablesServicePortFallback is enabled, DDS will attempt to bind to any available port if the specified port is unavailable.

Implementation

static Future<DartDevelopmentService> startDartDevelopmentService(
  Uri remoteVmServiceUri, {
  Uri? serviceUri,
  bool enableAuthCodes = true,
  bool ipv6 = false,
  bool enableServicePortFallback = false,
  List<String> cachedUserTags = const [],
  DevToolsConfiguration? devToolsConfiguration,
  bool logRequests = false,
  UriConverter? uriConverter,
}) async {
  if (!remoteVmServiceUri.isScheme('http')) {
    throw ArgumentError(
      'remoteVmServiceUri must have an HTTP scheme. Actual: ${remoteVmServiceUri.scheme}',
    );
  }
  if (serviceUri != null) {
    if (!serviceUri.isScheme('http')) {
      throw ArgumentError(
        'serviceUri must have an HTTP scheme. Actual: ${serviceUri.scheme}',
      );
    }

    // If provided an address to bind to, ensure it uses a protocol consistent
    // with that used to spawn DDS.
    final addresses = await InternetAddress.lookup(serviceUri.host);

    try {
      // Check to see if there's a valid address.
      addresses.firstWhere(
        (a) => (a.type ==
            (ipv6 ? InternetAddressType.IPv6 : InternetAddressType.IPv4)),
      );
    } on StateError {
      // Could not find a valid address.
      throw ArgumentError(
        "serviceUri '$serviceUri' is not an IPv${ipv6 ? "6" : "4"} address.",
      );
    }
  }

  final service = DartDevelopmentServiceImpl(
    remoteVmServiceUri,
    serviceUri,
    enableAuthCodes,
    cachedUserTags,
    ipv6,
    devToolsConfiguration,
    logRequests,
    enableServicePortFallback,
    uriConverter,
  );
  await service.startService();
  return service;
}