You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cloudsolutions-atoms/lib/modules/demo_module/provider/demo_provider.dart

90 lines
3.5 KiB
Dart

import 'package:flutter/cupertino.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:http/http.dart';
import 'package:test_sa/controllers/api_routes/api_manager.dart';
import 'package:test_sa/controllers/api_routes/urls.dart';
import 'package:test_sa/modules/demo_module/models/demo_request_model.dart';
import 'package:test_sa/modules/loan_module/models/loan_request_model.dart';
import 'dart:convert';
class DemoProvider extends ChangeNotifier {
Future<bool> addDemoRequest(Map<String, dynamic> body) async {
try {
Response response = await ApiManager.instance.post(URLs.addDemoRequest, body: body, showToast: false);
if (response.statusCode >= 200 && response.statusCode < 300) {
String message = (jsonDecode(response.body)["data"] ?? "") + " " + (jsonDecode(response.body)["message"] ?? "");
Fluttertoast.showToast(msg: message ?? "", toastLength: Toast.LENGTH_LONG);
return true;
}
return false;
} catch (error) {
return false;
}
}
bool isLoading = false;
Future<DemoRequestModel?> getDemoById(int id) async {
DemoRequestModel? demoRequestModel;
try {
Response response = await ApiManager.instance.get(URLs.getDemoRequestById + "/$id");
if (response.statusCode >= 200 && response.statusCode < 300) {
demoRequestModel = DemoRequestModel.fromJson(json.decode(response.body)["data"]);
}
} catch (error) {
print(error);
}
return demoRequestModel;
}
Future<bool> acceptRejectRequest({required int requestId, required bool status}) async {
try {
Map<String,dynamic> payload = {
"demoRequestId": requestId,
"isApproved": status
};
Response response = await ApiManager.instance.post(URLs.updateDemoRequestByAssessor, body: payload, showToast: false);
if (response.statusCode >= 200 && response.statusCode < 300) {
String message = (jsonDecode(response.body)["data"] ?? "") + " " + (jsonDecode(response.body)["message"] ?? "");
Fluttertoast.showToast(msg: message ?? "", toastLength: Toast.LENGTH_LONG);
return true;
}
return false;
} catch (error) {
return false;
}
}
Future<bool> updateDemoRequest(Map<String, dynamic> body) async {
try {
Response response = await ApiManager.instance.post(URLs.updateDemoRequest, body: body, showToast: false);
if (response.statusCode >= 200 && response.statusCode < 300) {
String message = (jsonDecode(response.body)["data"] ?? "") + " " + (jsonDecode(response.body)["message"] ?? "");
Fluttertoast.showToast(msg: message ?? "", toastLength: Toast.LENGTH_LONG);
return true;
}
return false;
} catch (error) {
return false;
}
}
Future<bool> updateDemoPeriod({required int demoPeriodId, required int requestId,required bool isUpdateRequired}) async {
try {
Map<String,dynamic> payload ={
"demoRequestId": requestId,
"demoPeriodId": demoPeriodId,
"isDemoPeriodExtentionRequired": isUpdateRequired
};
Response response = await ApiManager.instance.post(URLs.updateDemoPeriodByRequester, body: payload, showToast: false);
if (response.statusCode >= 200 && response.statusCode < 300) {
String message = (jsonDecode(response.body)["data"] ?? "") + " " + (jsonDecode(response.body)["message"] ?? "");
Fluttertoast.showToast(msg: message ?? "", toastLength: Toast.LENGTH_LONG);
return true;
}
return false;
} catch (error) {
return false;
}
}
}