Initial commit: Penyerahan final Source code Tugas Akhir
This commit is contained in:
34
lib/providers/posting_announcement_reply_provider.dart
Normal file
34
lib/providers/posting_announcement_reply_provider.dart
Normal file
@ -0,0 +1,34 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:initial_folder/services/announcement_service.dart';
|
||||
|
||||
enum ResultState { uninitilized, loading, failed, success }
|
||||
|
||||
class PostingAnnouncementReplyProvider with ChangeNotifier {
|
||||
ResultState _state = ResultState.uninitilized;
|
||||
|
||||
ResultState get state => _state;
|
||||
|
||||
Future<bool> postAnnouncementReply(String textBody, String idAnnouncmenet,
|
||||
String tokenAnnouncement, String idAnnouncement) async {
|
||||
try {
|
||||
_state = ResultState.loading;
|
||||
notifyListeners();
|
||||
|
||||
bool response = await AnnouncementService()
|
||||
.replyAnnouncement(tokenAnnouncement, textBody, idAnnouncement);
|
||||
if (response) {
|
||||
_state = ResultState.success;
|
||||
notifyListeners();
|
||||
return true;
|
||||
} else {
|
||||
_state = ResultState.failed;
|
||||
notifyListeners();
|
||||
return false;
|
||||
}
|
||||
} catch (e) {
|
||||
_state = ResultState.failed;
|
||||
notifyListeners();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user