Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- part of 'controllers.dart';
- class ArticleCategoryController extends GetxController {
- ArticleResult? _articleResult;
- String _message = '';
- late ResultState _state;
- ArticleResult? get articleResult => _articleResult;
- String get message => _message;
- ResultState get state => _state;
- // String? category;
- // @override
- // void onInit() {
- // fetchNewsCategory(category ?? '');
- // super.onInit();
- // }
- ArticleCategoryController({required String category}) {
- fetchNewsCategory(category);
- }
- Future<dynamic> fetchNewsCategory(String category) async {
- try {
- _state = ResultState.Loading;
- update();
- final article = await ArticleService().fetchArticlesCategory(category);
- if(article.articles.isEmpty) {
- _state = ResultState.NoData;
- _articleResult = null;
- update();
- return _message = 'Empty Data';
- } else {
- _state = ResultState.HasData;
- update();
- return _articleResult = article;
- }
- } catch(e) {
- _state = ResultState.Error;
- update();
- return _message = 'Error: $e';
- }
- }
- @override
- void onClose() {
- super.onClose();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement