[flutter_tools] handle NPE in list views method(#59626)
Fixes #59608 The VmService getter can be null, handle that in the listViews method. NNBD when
This commit is contained in:
@@ -841,9 +841,14 @@ abstract class ResidentRunner {
|
||||
|
||||
/// List the attached flutter views.
|
||||
Future<List<FlutterView>> listFlutterViews() async {
|
||||
return (await Future.wait(
|
||||
flutterDevices.map((FlutterDevice d) => d.vmService.getFlutterViews()))
|
||||
).expand((List<FlutterView> views) => views).toList();
|
||||
final List<List<FlutterView>> views = await Future.wait(<Future<List<FlutterView>>>[
|
||||
for (FlutterDevice device in flutterDevices)
|
||||
if (device.vmService != null)
|
||||
device.vmService.getFlutterViews()
|
||||
]);
|
||||
return views
|
||||
.expand((List<FlutterView> viewList) => viewList)
|
||||
.toList();
|
||||
}
|
||||
|
||||
/// Write the SkSL shaders to a zip file in build directory.
|
||||
|
||||
@@ -1044,6 +1044,16 @@ void main() {
|
||||
expect(fakeVmServiceHost.hasRemainingExpectations, false);
|
||||
}));
|
||||
|
||||
testUsingContext('listViews handles a null VM service', () => testbed.run(() async {
|
||||
final FlutterDevice device = FlutterDevice(mockDevice, buildInfo: BuildInfo.debug);
|
||||
final ResidentRunner residentRunner = HotRunner(
|
||||
<FlutterDevice>[device],
|
||||
);
|
||||
|
||||
expect(await residentRunner.listFlutterViews(), isEmpty);
|
||||
}));
|
||||
|
||||
|
||||
testUsingContext('ResidentRunner debugDumpApp calls flutter device', () => testbed.run(() async {
|
||||
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
|
||||
await residentRunner.debugDumpApp();
|
||||
|
||||
Reference in New Issue
Block a user