Repository navigation
feat: Keep the DevTools component tree and selection up to date - #4222
Merged
Merged
Conversation
IncrementalNumberFormField replaced its text whenever a new value came in. That is fine while values only arrive on a manual refresh, but once the selected component is polled, a poll would overwrite what the user is typing. A focused field now keeps its text when a new value arrives, and shows the latest value when it loses focus. If no new value arrived while it was focused, the typed value is kept. Submitting the field or tapping outside of it removes the focus. The angle field tests now remove the focus before the value is read back from the game, since a focused field ignores it. Tested with new widget tests for IncrementalNumberFormField; all flame_devtools tests pass.
The component tree and the selected component in the DevTools extension only updated through the manual refresh button, so their values went stale as soon as the game moved on (flame-engine#4173). The extension now polls the game while it is connected: the selected component every 100 ms, and the tree every second, since the game builds the whole tree with the toString and attributes of every component on each call. A Poller never starts a poll while the previous one is still running. A "Live" switch in the tree header turns polling off; the refresh button still works. The tree used to be rebuilt from scratch when its structure changed, which collapsed every node. It is now updated in place: nodes of components that are still in the game are kept with their expansion state, and only their data is replaced. The selected component section listens to the data of its node, so its toString updates too. The selection is cleared when its component is removed. Measured with a debug web build of a game with 1000 rotating boxes (about 2000 components): getComponentTree took 216 ms (659 KB), while a trivial service call took 97 ms, so building the tree costs about 120 ms, and a single component's attributes cost about the same as the trivial call. Tested with unit tests for Poller and the in-place tree sync, and by hand against a running game: values change in the form without a refresh, expanded nodes, selection and scroll position survive, and the Live switch stops and restarts the updates.
Resolves the conflicts with flame-engine#4227, which moved flame_devtools from package:flutter/material.dart to the package:flame_devtools/material.dart re-export. The new files and tests of this branch use the re-export too, and the tree sync test uses the new named isPositionComponent parameter of ComponentTreeNode. All flame_devtools tests pass and analyze is clean.
Contributor
Author
|
Merged the latest main after #4227 (conflicts resolved, tests green). @erickzanardo whenever you have a moment, happy to adjust the poll interval or anything else. |
Member
|
Can you add a screenshot/video of the result? |
Contributor
Author
Here’s a recording: the game on the left, DevTools on the right. It shows the values following the game, collapsed nodes staying collapsed, and the Live switch stopping and resuming the updates. flame-devtools-live-updates.webm |
erickzanardo
approved these changes
Nov 23, 2026
spydon
reviewed
Nov 23, 2026
refreshComponentTree was a static method that took the previous model, updated its tree in place and then returned a copy of it with the new component count. Since the model is mutated anyway, pretending that it is immutable only made it harder to follow, as pointed out in review. ComponentTreeModel is now a plain mutable class with a refresh method that updates the tree and the component count. The provider holds that single model, and the loader returns the component count, which the tree header shows. All flame_devtools tests pass and analyze is clean.
spydon
approved these changes
Nov 23, 2026
spydon
left a comment
Member
There was a problem hiding this comment.
It's quite a dirty solution, but I guess it buys some performance to not have the state immutable.
spydon
enabled auto-merge (squash)
November 23, 2026 14:56
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Keeps the component tree and the selected component in the
flame_devtoolsextension up to date while the game runs, as described in #4173. Before, they only updated through the manual refresh button.Pollernever starts a poll while the previous one is still running.toStringupdates too, and the selection is cleared when its component is removed.IncrementalNumberFormFieldno longer overwrites a value that is being edited. A focused field keeps its text and shows the latest value when it loses focus. Submitting or tapping outside of the field removes the focus.doc/flame/other/debug.mddescribes the live updates.Cost of polling, measured on a debug web build of a game with 1000 rotating boxes (about 2000 components):
getPaused(trivial call, for the round-trip overhead)getPositionComponentAttributesgetComponentTree(659 KB)So building the tree costs about 120 ms on that scene, and polling a single component costs about the same as the round trip. Open question: with a 1 s interval, that is roughly 12% of the game's time on a big scene in debug mode. Happy to change the interval, or make it slower on big trees, if you prefer.
Testing:
Poller(one poll per interval, no overlapping polls, inactive, failed polls, stopping) and for the in-place tree sync (kept nodes and their expansion, updated data, removed and added components).IncrementalNumberFormField. The angle field tests now remove the focus before reading a value back from the game.Screenshot and recording:
flame-devtools-live-updates.webm
Checklist
docsand added dartdoc comments with///.examplesordocs.Breaking Change?
Related Issues
Closes #4173