text stringlengths 1 372 |
|---|
} |
<code_end> |
<topic_end> |
<topic_start> |
highlight repaints |
this option draws a border around all render boxes |
that changes color every time that box repaints. |
this rotating rainbow of colors is useful for finding parts of your app |
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> |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.