Skip to content

Commit 1371b8d

Browse files
[flutter_tools] Fix null check errors in attach command (#107864)
1 parent 8dfad23 commit 1371b8d

3 files changed

Lines changed: 197 additions & 87 deletions

File tree

packages/flutter_tools/lib/src/commands/attach.dart

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,11 @@ known, it can be explicitly provided to attach via the command-line, e.g.
215215
Future<FlutterCommandResult> runCommand() async {
216216
await _validateArguments();
217217

218-
final Device device = await (findTargetDevice() as FutureOr<Device>);
218+
final Device? device = await findTargetDevice();
219+
220+
if (device == null) {
221+
throwToolExit('Did not find any valid target devices.');
222+
}
219223

220224
final Artifacts? overrideArtifacts = device.artifactOverrides ?? globals.artifacts;
221225
await context.run<void>(
@@ -272,7 +276,7 @@ known, it can be explicitly provided to attach via the command-line, e.g.
272276
} else if ((device is IOSDevice) || (device is IOSSimulator) || (device is MacOSDesignedForIPadDevice)) {
273277
final Uri? uriFromMdns =
274278
await MDnsObservatoryDiscovery.instance!.getObservatoryUri(
275-
appId!,
279+
appId,
276280
device,
277281
usesIpv6: usesIpv6,
278282
deviceVmservicePort: deviceVmservicePort,
@@ -317,12 +321,12 @@ known, it can be explicitly provided to attach via the command-line, e.g.
317321
try {
318322
int? result;
319323
if (daemon != null) {
320-
final ResidentRunner runner = await (createResidentRunner(
324+
final ResidentRunner runner = await createResidentRunner(
321325
observatoryUris: observatoryUri,
322326
device: device,
323327
flutterProject: flutterProject,
324328
usesIpv6: usesIpv6,
325-
) as FutureOr<ResidentRunner>);
329+
);
326330
late AppInstance app;
327331
try {
328332
app = await daemon.appDomain.launch(
@@ -351,12 +355,12 @@ known, it can be explicitly provided to attach via the command-line, e.g.
351355
return;
352356
}
353357
while (true) {
354-
final ResidentRunner runner = await (createResidentRunner(
358+
final ResidentRunner runner = await createResidentRunner(
355359
observatoryUris: observatoryUri,
356360
device: device,
357361
flutterProject: flutterProject,
358362
usesIpv6: usesIpv6,
359-
) as FutureOr<ResidentRunner>);
363+
);
360364
final Completer<void> onAppStart = Completer<void>.sync();
361365
TerminalHandler? terminalHandler;
362366
unawaited(onAppStart.future.whenComplete(() {
@@ -400,7 +404,7 @@ known, it can be explicitly provided to attach via the command-line, e.g.
400404
}
401405
}
402406

403-
Future<ResidentRunner?> createResidentRunner({
407+
Future<ResidentRunner> createResidentRunner({
404408
required Stream<Uri> observatoryUris,
405409
required Device device,
406410
required FlutterProject flutterProject,
@@ -452,7 +456,7 @@ known, it can be explicitly provided to attach via the command-line, e.g.
452456
}
453457

454458
class HotRunnerFactory {
455-
HotRunner? build(
459+
HotRunner build(
456460
List<FlutterDevice> devices, {
457461
required String target,
458462
required DebuggingOptions debuggingOptions,

packages/flutter_tools/lib/src/mdns_discovery.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class MDnsObservatoryDiscovery {
145145
}
146146
}
147147

148-
Future<Uri?> getObservatoryUri(String applicationId, Device device, {
148+
Future<Uri?> getObservatoryUri(String? applicationId, Device device, {
149149
bool usesIpv6 = false,
150150
int? hostVmservicePort,
151151
int? deviceVmservicePort,

0 commit comments

Comments
 (0)