Files
Vocasia-LMS-Mobile-apps--TA…/lib/providers/like_or_unlike_provider.dart

33 lines
817 B
Dart

import 'package:flutter/material.dart';
import 'package:initial_folder/services/qna_service.dart';
enum ResultState { uninitilized, loading, failed, success }
class LikeOrUnlikeProvider with ChangeNotifier {
ResultState _state = ResultState.uninitilized;
ResultState get state => _state;
//Posting QNA
Future<bool> likeOrUnlike(int idQna) async {
try {
_state = ResultState.loading;
notifyListeners();
bool response = await QnaService().likeOrLike(idQna);
if (response) {
_state = ResultState.success;
notifyListeners();
return true;
} else {
_state = ResultState.failed;
notifyListeners();
return false;
}
} catch (e) {
_state = ResultState.failed;
notifyListeners();
return false;
}
}
}