import 'package:english_learning/core/services/repositories/section_repository.dart'; import 'package:english_learning/features/learning/modules/model/section_model.dart'; import 'package:flutter/foundation.dart'; class SectionProvider extends ChangeNotifier { final SectionRepository _repository = SectionRepository(); List
_sections = []; bool _isLoading = false; dynamic _error; List
get sections => _sections; bool get isLoading => _isLoading; String? get error => _error; void resetData() { _sections = []; _error = null; _isLoading = true; notifyListeners(); } Future fetchSections(String token) async { try { // Set loading state _isLoading = true; _error = null; notifyListeners(); // Fetch sections _sections = await _repository.getSections(token); // Reset loading state _isLoading = false; _error = null; notifyListeners(); } catch (e) { // Handle error _isLoading = false; _error = e; notifyListeners(); // Rethrow the error to be handled by the caller rethrow; } } }