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