const constructor tạo hằng số compile-time, bất biến và có thể tái sử dụng.
- Widget
constbỏ qua rebuild nếu tham số không đổi, cải thiện hiệu năng đáng kể. - Flutter có thể gộp các đối tượng
constgiống nhau thành một instance, giảm bộ nhớ. - Luôn dùng
constcho widget với tham số cố định:const Text("Hello"). - Tránh tạo
UniqueKeytrongconstvì sẽ mất lợi ích.
A const constructor creates compile-time constants that are immutable and reusable. const widgets bypass rebuilds if their parameters don't change, significantly improving performance.
Flutter can merge identical const objects into a single instance, reducing memory usage.