31 lines
856 B
Dart
31 lines
856 B
Dart
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<Section> _sections = [];
|
|
bool _isLoading = false;
|
|
String? _error;
|
|
|
|
List<Section> get sections => _sections;
|
|
bool get isLoading => _isLoading;
|
|
String? get error => _error;
|
|
|
|
Future<void> fetchSections(String token) async {
|
|
_isLoading = true;
|
|
_error = null;
|
|
notifyListeners();
|
|
|
|
try {
|
|
_sections = await _repository.getSections(token);
|
|
_isLoading = false;
|
|
notifyListeners();
|
|
} catch (e) {
|
|
_isLoading = false;
|
|
_error = e.toString();
|
|
notifyListeners();
|
|
}
|
|
}
|
|
}
|