虽然 Flutter 在默认情况下性能良好,但优化性能涉及最小化不必要的 rebuilds、高效的 list rendering、正确使用 const、避免在 build 中进行昂贵操作以及进行 profiling。理解这些可以保持应用流畅(60/120 fps)。
最小化不必要的 rebuilds
✓ Use CONST constructors where possible → const widgets aren't rebuilt (huge win)
const Text('Static') // not rebuilt unnecessarily
✓ Keep setState/rebuild scope SMALL → rebuild only what changed (extract widgets so
state changes rebuild a small subtree, not the whole screen)
✓ Use targeted state management (rebuild only widgets that depend on changed state)
✓ Don't rebuild large trees for small changes
