start static method
Implementation
static Future<DartDevelopmentServiceLauncher> start({
required Uri remoteVmServiceUri,
Uri? serviceUri,
bool enableAuthCodes = true,
bool serveDevTools = false,
Uri? devToolsServerAddress,
bool enableServicePortFallback = false,
List<String> cachedUserTags = const <String>[],
String? dartExecutable,
// TODO(chingjun): Change the type to String once flutter_tools is migrated.
Object? google3WorkspaceRoot,
}) async {
assert(google3WorkspaceRoot == null ||
google3WorkspaceRoot is Uri ||
google3WorkspaceRoot is String);
final process = await Process.start(
dartExecutable ?? Platform.executable,
<String>[
'development-service',
'--${DartDevelopmentServiceOptions.vmServiceUriOption}=$remoteVmServiceUri',
if (serviceUri != null) ...<String>[
'--${DartDevelopmentServiceOptions.bindAddressOption}=${serviceUri.host}',
'--${DartDevelopmentServiceOptions.bindPortOption}=${serviceUri.port}',
],
if (!enableAuthCodes)
'--${DartDevelopmentServiceOptions.disableServiceAuthCodesFlag}',
if (serveDevTools)
'--${DartDevelopmentServiceOptions.serveDevToolsFlag}',
if (devToolsServerAddress != null)
'--${DartDevelopmentServiceOptions.devToolsServerAddressOption}=$devToolsServerAddress',
if (enableServicePortFallback)
'--${DartDevelopmentServiceOptions.enableServicePortFallbackFlag}',
for (final String tag in cachedUserTags)
'--${DartDevelopmentServiceOptions.cachedUserTagsOption}=$tag',
if (google3WorkspaceRoot != null)
'--${DartDevelopmentServiceOptions.google3WorkspaceRootOption}=$google3WorkspaceRoot',
],
);
final completer = Completer<DartDevelopmentServiceLauncher>();
late StreamSubscription<Object?> stderrSub;
stderrSub = process.stderr
.transform(utf8.decoder)
.transform(json.decoder)
.listen((Object? result) {
if (result
case {
'state': 'started',
'ddsUri': final String ddsUriStr,
}) {
final ddsUri = Uri.parse(ddsUriStr);
final devToolsUriStr = result['devToolsUri'] as String?;
final devToolsUri =
devToolsUriStr == null ? null : Uri.parse(devToolsUriStr);
final dtdUriStr =
(result['dtd'] as Map<String, Object?>?)?['uri'] as String?;
final dtdUri = dtdUriStr == null ? null : Uri.parse(dtdUriStr);
completer.complete(
DartDevelopmentServiceLauncher._(
process: process,
uri: ddsUri,
devToolsUri: devToolsUri,
dtdUri: dtdUri,
),
);
} else if (result
case {
'state': 'error',
'error': final String error,
}) {
final Map<String, Object?>? exceptionDetails =
result['ddsExceptionDetails'] as Map<String, Object?>?;
completer.completeError(
exceptionDetails != null
? DartDevelopmentServiceException.fromJson(exceptionDetails)
: StateError(error),
);
} else {
throw StateError('Unexpected result from DDS: $result');
}
stderrSub.cancel();
});
return completer.future;
}