State & Data
Provider architecture
A useful architecture separates presentation from application state and infrastructure. Provider can expose state objects to the widget tree without making every widget responsible for data access.
dart
class InventoryProvider extends ChangeNotifier {
final InventoryRepository repository;
List<Item> items = [];
Future<void> load() async {
items = await repository.load();
notifyListeners();
}
}Practical structure
- models/ — immutable or serializable domain objects
- providers/ — ChangeNotifier state and commands
- services/ — storage, notifications and integrations
- screens/ — page-level composition
- widgets/ — reusable visual components
Lesson complete?Use the next lesson to continue the learning path.