Provider là thư viện state management dùng ChangeNotifier để thông báo listener khi state thay đổi.
- Widget lắng nghe qua
Consumerhoặccontext.watch<T>()và chỉ rebuild khi dữ liệu chúng phụ thuộc thay đổi. - Provider nhẹ và phù hợp cho app nhỏ đến vừa, nhưng Flutter team hiện nay khuyến nghị Riverpod cho dự án mới vì type-safe hơn và không phụ thuộc
BuildContext. - Bọc app với
MultiProvider, định nghĩa provider cho data, và consume trong widget.
Provider uses ChangeNotifier to notify listeners when state changes.
- Widgets listen via
Consumerorcontext.watch<T>()and rebuild only when data they depend on changes. - Provider is lightweight and suitable for small-to-medium apps, but the Flutter team now recommends Riverpod for new projects as it is fully type-safe and does not depend on
BuildContext.