From b48b31b524acdf87ba9b0fd8581f3e2a3694f511 Mon Sep 17 00:00:00 2001 From: Elliott Brooks <21270878+elliette@users.noreply.github.com> Date: Wed, 11 Dec 2024 16:35:33 -0800 Subject: [PATCH] Auto-refresh the widget tree on navigation events (#8622) --- .../inspector_settings_dialog.dart | 4 ++-- .../inspector_v2/inspector_controller.dart | 17 ++++++++++++----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/packages/devtools_app/lib/src/screens/inspector_shared/inspector_settings_dialog.dart b/packages/devtools_app/lib/src/screens/inspector_shared/inspector_settings_dialog.dart index 1d86b140f35..624bb867885 100644 --- a/packages/devtools_app/lib/src/screens/inspector_shared/inspector_settings_dialog.dart +++ b/packages/devtools_app/lib/src/screens/inspector_shared/inspector_settings_dialog.dart @@ -52,9 +52,9 @@ class FlutterInspectorSettingsDialog extends StatelessWidget { notifier: preferences.inspector.autoRefreshEnabled as ValueNotifier, - title: 'Enable auto-refreshing of the widget tree', + title: 'Enable widget tree auto-refreshing', description: - 'The widget tree will automatically be refreshed after a hot-reload.', + 'The widget tree will automatically refresh after a hot-reload or navigation event.', gaItem: gac.inspectorAutoRefreshEnabled, ), ] else ...[ diff --git a/packages/devtools_app/lib/src/screens/inspector_v2/inspector_controller.dart b/packages/devtools_app/lib/src/screens/inspector_v2/inspector_controller.dart index 0add997ae1f..e265f4d3364 100644 --- a/packages/devtools_app/lib/src/screens/inspector_v2/inspector_controller.dart +++ b/packages/devtools_app/lib/src/screens/inspector_v2/inspector_controller.dart @@ -445,16 +445,23 @@ class InspectorController extends DisposableController } bool _receivedIsolateReloadEvent = false; + bool _receivedFlutterNavigationEvent = false; Future _maybeAutoRefreshInspector(Event event) async { if (!preferences.inspector.autoRefreshEnabled.value) return; - // It is not sufficent to wait for the isolate reload event, because Flutter - // might not have re-painted the app. Instead, we need to wait for the first - // frame AFTER the isolate reload event in order to request the new tree. + // It is not sufficent to wait for the navigation and isolate reload events + // only, because Flutter might not have re-painted the app. Instead, we need + // to wait for the first frame AFTER the isolate reload or navigation event + // in order to request the new tree. if (event.kind == EventKind.kExtension) { - if (!_receivedIsolateReloadEvent) return; - if (event.extensionKind == 'Flutter.Frame') { + final extensionEventKind = event.extensionKind; + if (extensionEventKind == 'Flutter.Navigation') { + _receivedFlutterNavigationEvent = true; + } + if ((_receivedFlutterNavigationEvent || _receivedIsolateReloadEvent) && + extensionEventKind == 'Flutter.Frame') { + _receivedFlutterNavigationEvent = false; _receivedIsolateReloadEvent = false; await refreshInspector(); }