@@ -22,6 +22,7 @@ import 'package:flutter/cupertino.dart';
2222import 'package:flutter/foundation.dart' ;
2323import 'package:vm_service/vm_service.dart' ;
2424
25+ import '../../service/vm_service_wrapper.dart' ;
2526import '../console/primitives/simple_items.dart' ;
2627import '../globals.dart' ;
2728import '../utils/utils.dart' ;
@@ -501,13 +502,22 @@ abstract class InspectorObjectGroupBase
501502 /// attempt carefully cancel futures.
502503 @override
503504 Future <void > dispose () {
504- // No need to dispose the group if the isolate is already gone.
505- final disposeComplete = inspectorService.isolateRef != null
506- ? invokeVoidServiceMethod (
507- WidgetInspectorServiceExtensions .disposeGroup.name,
508- groupName,
509- )
510- : Future <void >.value ();
505+ var disposeComplete = Future <void >.value ();
506+ try {
507+ // Only dispose the group if the isolate still exists.
508+ if (inspectorService.isolateRef != null ) {
509+ disposeComplete = invokeVoidServiceMethod (
510+ WidgetInspectorServiceExtensions .disposeGroup.name,
511+ groupName,
512+ );
513+ }
514+ } on RPCError catch (e) {
515+ if (! e.isServiceDisposedError) {
516+ // Swallow exceptions related to trying to dispose an Inspector group on
517+ // an already disposed service connection. Otherwise, rethrow.
518+ rethrow ;
519+ }
520+ }
511521 disposed = true ;
512522 return disposeComplete;
513523 }
0 commit comments