2
2
// for details. All rights reserved. Use of this source code is governed by a
3
3
// BSD-style license that can be found in the LICENSE file.
4
4
5
+ // @dart=2.10
6
+
5
7
/// A library used to spawn the Dart Developer Service, used to communicate
6
8
/// with a Dart VM Service instance.
7
9
library dds;
@@ -39,12 +41,15 @@ abstract class DartDevelopmentService {
39
41
/// default.
40
42
static Future <DartDevelopmentService > startDartDevelopmentService (
41
43
Uri remoteVmServiceUri, {
42
- Uri ? serviceUri,
44
+ Uri serviceUri,
43
45
bool enableAuthCodes = true ,
44
46
bool ipv6 = false ,
45
- DevToolsConfiguration ? devToolsConfiguration,
47
+ DevToolsConfiguration devToolsConfiguration = const DevToolsConfiguration () ,
46
48
bool logRequests = false ,
47
49
}) async {
50
+ if (remoteVmServiceUri == null ) {
51
+ throw ArgumentError .notNull ('remoteVmServiceUri' );
52
+ }
48
53
if (remoteVmServiceUri.scheme != 'http' ) {
49
54
throw ArgumentError (
50
55
'remoteVmServiceUri must have an HTTP scheme. Actual: ${remoteVmServiceUri .scheme }' ,
@@ -60,15 +65,12 @@ abstract class DartDevelopmentService {
60
65
// If provided an address to bind to, ensure it uses a protocol consistent
61
66
// with that used to spawn DDS.
62
67
final addresses = await InternetAddress .lookup (serviceUri.host);
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.
68
+ final address = addresses.firstWhere (
69
+ (a) => (a.type ==
70
+ (ipv6 ? InternetAddressType .IPv6 : InternetAddressType .IPv4 )),
71
+ orElse: () => null ,
72
+ );
73
+ if (address == null ) {
72
74
throw ArgumentError (
73
75
"serviceUri '$serviceUri ' is not an IPv${ipv6 ? "6" : "4" } address." ,
74
76
);
@@ -113,24 +115,24 @@ abstract class DartDevelopmentService {
113
115
/// [DartDevelopmentService] via HTTP.
114
116
///
115
117
/// Returns `null` if the service is not running.
116
- Uri ? get uri;
118
+ Uri get uri;
117
119
118
120
/// The [Uri] VM service clients can use to communicate with this
119
121
/// [DartDevelopmentService] via server-sent events (SSE).
120
122
///
121
123
/// Returns `null` if the service is not running.
122
- Uri ? get sseUri;
124
+ Uri get sseUri;
123
125
124
126
/// The [Uri] VM service clients can use to communicate with this
125
127
/// [DartDevelopmentService] via a [WebSocket] .
126
128
///
127
129
/// Returns `null` if the service is not running.
128
- Uri ? get wsUri;
130
+ Uri get wsUri;
129
131
130
132
/// The HTTP [Uri] of the hosted DevTools instance.
131
133
///
132
134
/// Returns `null` if DevTools is not running.
133
- Uri ? get devToolsUri;
135
+ Uri get devToolsUri;
134
136
135
137
/// Set to `true` if this instance of [DartDevelopmentService] is accepting
136
138
/// requests.
@@ -178,8 +180,8 @@ class DartDevelopmentServiceException implements Exception {
178
180
179
181
class DevToolsConfiguration {
180
182
const DevToolsConfiguration ({
181
- required this .customBuildDirectoryPath,
182
183
this .enable = false ,
184
+ this .customBuildDirectoryPath,
183
185
});
184
186
185
187
final bool enable;
0 commit comments