Skip to content

Commit

Permalink
Auto-refresh the widget tree on navigation events (#8622)
Browse files Browse the repository at this point in the history
  • Loading branch information
elliette authored Dec 12, 2024
1 parent e6b6000 commit b48b31b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ class FlutterInspectorSettingsDialog extends StatelessWidget {
notifier:
preferences.inspector.autoRefreshEnabled
as ValueNotifier<bool?>,
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 ...[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,16 +445,23 @@ class InspectorController extends DisposableController
}

bool _receivedIsolateReloadEvent = false;
bool _receivedFlutterNavigationEvent = false;

Future<void> _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();
}
Expand Down

0 comments on commit b48b31b

Please sign in to comment.