Summary - Performance
- Flutter course
- Expert
- Lesson 10/39
- 4 min
Combine profile, RepaintBoundary and const to optimize.
Summary - Performance
When optimizing an app, three tools work together: use profile mode to find bottlenecks, RepaintBoundary to isolate unnecessary paint areas, and const to avoid recreating constant widgets. Together they bring a big performance gain.
RepaintBoundary(
child: const Text('Sablon'),
)
// measure the bottleneck in profile modePractice Combine RepaintBoundary and const
In main, create a RepaintBoundary widget: give const Text('Sablon') as child. Print the widget's runtimeType.
Starter code
import 'package:flutter/material.dart';
void main() {
// RepaintBoundary oluştur, child Sablon metnini const olarak tutsun
// runtimeType yazdır
}Sample solution
import 'package:flutter/material.dart';
void main() {
final widget = RepaintBoundary(
child: const Text('Sablon'),
);
print(widget.runtimeType);
}Expected output
RepaintBoundary
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What do RepaintBoundary and const provide together?
- Better state management
- Reduces repaint and rebuild cost Correct answer
- Only memory saving
- Faster HTTP
Explanation: RepaintBoundary prevents unnecessary paint, const prevents unnecessary rebuild; together they reduce drawing and recreation cost.
2 const RepaintBoundary child
RepaintBoundary(
child: ____ Text('Sablon'),
)
RepaintBoundary(
child: const Text('Sablon'),
)
Explanation: const Text('Sablon') is created at compile time; new, final and var produce a runtime object and incur rebuild cost.
3 Optimization matches
| Term | Meaning |
|---|---|
profile |
Bottleneck measurement |
RepaintBoundary |
Paint area isolation |
const |
Constant widget |
ListView |
Efficient list |