22// for details. All rights reserved. Use of this source code is governed by a
33// BSD-style license that can be found in the LICENSE file.
44
5- // @dart=2.10
6-
75/// A library used to spawn the Dart Developer Service, used to communicate
86/// with a Dart VM Service instance.
97library dds;
@@ -41,15 +39,12 @@ abstract class DartDevelopmentService {
4139 /// default.
4240 static Future <DartDevelopmentService > startDartDevelopmentService (
4341 Uri remoteVmServiceUri, {
44- Uri serviceUri,
42+ Uri ? serviceUri,
4543 bool enableAuthCodes = true ,
4644 bool ipv6 = false ,
47- DevToolsConfiguration devToolsConfiguration = const DevToolsConfiguration () ,
45+ DevToolsConfiguration ? devToolsConfiguration,
4846 bool logRequests = false ,
4947 }) async {
50- if (remoteVmServiceUri == null ) {
51- throw ArgumentError .notNull ('remoteVmServiceUri' );
52- }
5348 if (remoteVmServiceUri.scheme != 'http' ) {
5449 throw ArgumentError (
5550 'remoteVmServiceUri must have an HTTP scheme. Actual: ${remoteVmServiceUri .scheme }' ,
@@ -65,12 +60,15 @@ abstract class DartDevelopmentService {
6560 // If provided an address to bind to, ensure it uses a protocol consistent
6661 // with that used to spawn DDS.
6762 final addresses = await InternetAddress .lookup (serviceUri.host);
68- final address = addresses.firstWhere (
69- (a) => (a.type ==
70- (ipv6 ? InternetAddressType .IPv6 : InternetAddressType .IPv4 )),
71- orElse: () => null ,
72- );
73- if (address == null ) {
63+
64+ try {
65+ // Check to see if there's a valid address.
66+ addresses.firstWhere (
67+ (a) => (a.type ==
68+ (ipv6 ? InternetAddressType .IPv6 : InternetAddressType .IPv4 )),
69+ );
70+ } on StateError {
71+ // Could not find a valid address.
7472 throw ArgumentError (
7573 "serviceUri '$serviceUri ' is not an IPv${ipv6 ? "6" : "4" } address." ,
7674 );
@@ -115,24 +113,24 @@ abstract class DartDevelopmentService {
115113 /// [DartDevelopmentService] via HTTP.
116114 ///
117115 /// Returns `null` if the service is not running.
118- Uri get uri;
116+ Uri ? get uri;
119117
120118 /// The [Uri] VM service clients can use to communicate with this
121119 /// [DartDevelopmentService] via server-sent events (SSE).
122120 ///
123121 /// Returns `null` if the service is not running.
124- Uri get sseUri;
122+ Uri ? get sseUri;
125123
126124 /// The [Uri] VM service clients can use to communicate with this
127125 /// [DartDevelopmentService] via a [WebSocket] .
128126 ///
129127 /// Returns `null` if the service is not running.
130- Uri get wsUri;
128+ Uri ? get wsUri;
131129
132130 /// The HTTP [Uri] of the hosted DevTools instance.
133131 ///
134132 /// Returns `null` if DevTools is not running.
135- Uri get devToolsUri;
133+ Uri ? get devToolsUri;
136134
137135 /// Set to `true` if this instance of [DartDevelopmentService] is accepting
138136 /// requests.
@@ -180,8 +178,8 @@ class DartDevelopmentServiceException implements Exception {
180178
181179class DevToolsConfiguration {
182180 const DevToolsConfiguration ({
181+ required this .customBuildDirectoryPath,
183182 this .enable = false ,
184- this .customBuildDirectoryPath,
185183 });
186184
187185 final bool enable;
0 commit comments