CodeBlanks Logo Icon CodeBlanks

Summary - Performance

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 mode

Practice Combine RepaintBoundary and const

In main, create a RepaintBoundary widget: give const Text('Sablon') as child. Print the widget's runtimeType.

Starter code

main.dart
import 'package:flutter/material.dart';

void main() {
  // RepaintBoundary oluştur, child Sablon metnini const olarak tutsun
  // runtimeType yazdır
}

Sample solution

main.dart
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

Question
RepaintBoundary(
  child: ____ Text('Sablon'),
)
Answer
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

All lessons in Expert