text stringlengths 1 474 |
|---|
that are repainting too often and potentially harming performance.For example, one small animation could be causing an entire page |
to repaint on every frame. |
Wrapping the animation in a RepaintBoundary widget limits |
the repainting to just the animation.Here the progress indicator causes its container to repaint: |
<code_start>class EverythingRepaintsPage extends StatelessWidget { |
const EverythingRepaintsPage({super.key}); |
@override |
Widget build(BuildContext context) { |
return Scaffold( |
appBar: AppBar(title: const Text('Repaint Example')), |
body: const Center( |
child: CircularProgressIndicator(), |
), |
); |
} |
}<code_end> |
Wrapping the progress indicator in a RepaintBoundary causes |
only that section of the screen to repaint: |
<code_start>class AreaRepaintsPage extends StatelessWidget { |
const AreaRepaintsPage({super.key}); |
@override |
Widget build(BuildContext context) { |
return Scaffold( |
appBar: AppBar(title: const Text('Repaint Example')), |
body: const Center( |
child: RepaintBoundary( |
child: CircularProgressIndicator(), |
), |
), |
); |
} |
}<code_end> |
RepaintBoundary widgets have tradeoffs. They can help with performance, |
but they also have an overhead of creating a new canvas, |
which uses additional memory.You can also enable this option in code: |
<code_start>import 'package:flutter/rendering.dart'; |
void highlightRepaints() { |
debugRepaintRainbowEnabled = true; |
}<code_end> |
<topic_end> |
<topic_start> |
Highlight oversized images |
This option highlights images that are too large by both inverting their colors |
and flipping them vertically:The highlighted images use more memory than is required; |
for example, a large 5MB image displayed at 100 by 100 pixels.Such images can cause poor performance, especially on lower-end devices |
and when you have many images, as in a list view, |
this performance hit can add up. |
Information about each image is printed in the debug console:Images are deemed too large if they use at least 128KB more than required.<topic_end> |
<topic_start>Fixing images |
Wherever possible, the best way to fix this problem is resizing |
the image asset file so it’s smaller.If this isn’t possible, you can use the cacheHeight and cacheWidth |
parameters on the Image constructor: |
<code_start>class ResizedImage extends StatelessWidget { |
const ResizedImage({super.key}); |
@override |
Widget build(BuildContext context) { |
return Image.asset( |
'dash.png', |
cacheHeight: 213, |
cacheWidth: 392, |
); |
} |
}<code_end> |
This makes the engine decode this image at the specified size, |
and reduces memory usage (decoding and storage is still more expensive |
than if the image asset itself was shrunk). |
The image is rendered to the constraints of the layout or width and height |
regardless of these parameters.This property can also be set in code: |
<code_start>void showOversizedImages() { |
debugInvertOversizedImages = true; |
}<code_end> |
<topic_end> |
<topic_start>More information |
You can learn more at the following link:<topic_end> |
<topic_start> |
Details Tree |
Select the Widget Details Tree tab to display the details tree for the |
selected widget. From here, you can gather useful information about a |
widget’s properties, render object, and children.<topic_end> |
<topic_start> |
Track widget creation |
Part of the functionality of the Flutter inspector is based on |
instrumenting the application code in order to better understand |
the source locations where widgets are created. The source |
instrumentation allows the Flutter inspector to present the |
widget tree in a manner similar to how the UI was defined |
in your source code. Without it, the tree of nodes in the |
widget tree are much deeper, and it can be more difficult to |
understand how the runtime widget hierarchy corresponds to |
your application’s UI.You can disable this feature by passing --no-track-widget-creation to |
the flutter run command.Here are examples of what your widget tree might look like |
with and without track widget creation enabled.Track widget creation enabled (default):Track widget creation disabled (not recommended):This feature prevents otherwise-identical const Widgets from |
being considered equal in debug builds. For more details, see |
the discussion on common problems when debugging.<topic_end> |
<topic_start> |
Inspector settings |
<topic_end> |
<topic_start> |
Enable hover inspection |
Hovering over any widget displays its properties and values.Toggling this value enables or disables the hover inspection functionality.<topic_end> |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.