Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MesenggerController extends GetxController {
- final _helper = MyHelper();
- var data = <Map<String, dynamic>>[].obs;
- final RxBool loading = true.obs;
- final RxBool finish = false.obs;
- Future<void> kirimPesan(String text) async {
- String token = await _helper.readStorage('token');
- String userID = await _helper.readStorage('userID');
- var url = Uri.parse('http://$ip/mesengger/insert');
- var headers = {'Content-Type': 'application/json'};
- var dataJson = {
- 'token': token,
- };
- var body = jsonEncode(dataJson);
- try {
- var response = await http.post(url, headers: headers, body: body);
- var parsedBody = jsonDecode(response.body);
- if (response.statusCode == 200) {
- Map<String, dynamic> responseMap = parsedBody;
- List<Map<String, dynamic>> dataList = responseMap['data'].cast<Map<String, dynamic>>();
- data.assignAll(dataList);
- loading.value = false;
- finish.value = true;
- } else {
- loading.value = false;
- finish.value = false;
- data.clear();
- }
- } catch (error) {
- loading.value = false;
- finish.value = false;
- data.clear();
- log('Error bro: $error');
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement