Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-refresh the widget tree on navigation events #8622

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading