22// Use of this source code is governed by a BSD-style license that can be
33// found in the LICENSE file.
44
5- // @dart=2.9
6-
75import 'dart:async' ;
86import 'dart:convert' ;
97import 'dart:io' as io;
@@ -48,7 +46,7 @@ class XCTestCommand extends PluginCommand {
4846 Future <void > run () async {
4947 String destination = getStringArg (_kiOSDestination);
5048 if (destination.isEmpty) {
51- final String simulatorId = await _findAvailableIphoneSimulator ();
49+ final String ? simulatorId = await _findAvailableIphoneSimulator ();
5250 if (simulatorId == null ) {
5351 print (_kFoundNoSimulatorsMessage);
5452 throw ToolExit (1 );
@@ -119,7 +117,7 @@ class XCTestCommand extends PluginCommand {
119117 workingDir: example, exitOnError: false );
120118 }
121119
122- Future <String > _findAvailableIphoneSimulator () async {
120+ Future <String ? > _findAvailableIphoneSimulator () async {
123121 // Find the first available destination if not specified.
124122 final List <String > findSimulatorsArguments = < String > [
125123 'simctl' ,
@@ -143,30 +141,40 @@ class XCTestCommand extends PluginCommand {
143141 final List <Map <String , dynamic >> runtimes =
144142 (simulatorListJson['runtimes' ] as List <dynamic >)
145143 .cast <Map <String , dynamic >>();
146- final Map <String , dynamic > devices =
147- simulatorListJson['devices' ] as Map <String , dynamic >;
144+ final Map <String , Object > devices =
145+ (simulatorListJson['devices' ] as Map <String , dynamic >)
146+ .cast <String , Object >();
148147 if (runtimes.isEmpty || devices.isEmpty) {
149148 return null ;
150149 }
151- String id;
150+ String ? id;
152151 // Looking for runtimes, trying to find one with highest OS version.
153- for (final Map <String , dynamic > runtimeMap in runtimes.reversed) {
154- if (! (runtimeMap['name' ] as String ).contains ('iOS' )) {
152+ for (final Map <String , dynamic > rawRuntimeMap in runtimes.reversed) {
153+ final Map <String , Object > runtimeMap =
154+ rawRuntimeMap.cast <String , Object >();
155+ if ((runtimeMap['name' ] as String ? )? .contains ('iOS' ) != true ) {
156+ continue ;
157+ }
158+ final String ? runtimeID = runtimeMap['identifier' ] as String ? ;
159+ if (runtimeID == null ) {
155160 continue ;
156161 }
157- final String runtimeID = runtimeMap['identifier' ] as String ;
158- final List <Map <String , dynamic >> devicesForRuntime =
159- (devices[runtimeID] as List <dynamic >).cast <Map <String , dynamic >>();
160- if (devicesForRuntime.isEmpty) {
162+ final List <Map <String , dynamic >>? devicesForRuntime =
163+ (devices[runtimeID] as List <dynamic >? )? .cast <Map <String , dynamic >>();
164+ if (devicesForRuntime == null || devicesForRuntime.isEmpty) {
161165 continue ;
162166 }
163167 // Looking for runtimes, trying to find latest version of device.
164- for (final Map <String , dynamic > device in devicesForRuntime.reversed) {
168+ for (final Map <String , dynamic > rawDevice in devicesForRuntime.reversed) {
169+ final Map <String , Object > device = rawDevice.cast <String , Object >();
165170 if (device['availabilityError' ] != null ||
166- (device['isAvailable' ] as bool == false )) {
171+ (device['isAvailable' ] as bool ? ) == false ) {
172+ continue ;
173+ }
174+ id = device['udid' ] as String ? ;
175+ if (id == null ) {
167176 continue ;
168177 }
169- id = device['udid' ] as String ;
170178 print ('device selected: $device ' );
171179 return id;
172180 }
0 commit comments