2024-05-23 15:43:13 +05:30
|
|
|
import 'dart:convert';
|
|
|
|
|
import 'dart:developer';
|
|
|
|
|
|
|
|
|
|
import 'package:dio/dio.dart';
|
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
|
import 'package:get/get.dart' hide Response;
|
|
|
|
|
import 'package:regroup/Global.dart';
|
2024-07-09 13:10:40 +05:30
|
|
|
import 'package:regroup/Common/base_manager.dart';
|
2024-08-14 13:49:57 +05:30
|
|
|
import 'package:regroup/Utils/dialogs.dart';
|
|
|
|
|
import 'package:regroup/resources/routes/route_name.dart';
|
2024-05-23 15:43:13 +05:30
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
|
|
|
|
|
|
import 'package:http/http.dart' as http;
|
|
|
|
|
|
2024-07-09 13:10:40 +05:30
|
|
|
import '../../entry_point_controller.dart';
|
2024-05-23 15:43:13 +05:30
|
|
|
|
2024-07-09 13:10:40 +05:30
|
|
|
class NetworkApiServices {
|
2024-05-23 15:43:13 +05:30
|
|
|
Dio dio = Dio();
|
|
|
|
|
final controllerEntryPoint = Get.put(EntryPointController());
|
|
|
|
|
|
2024-08-14 13:49:57 +05:30
|
|
|
String basicAuth =
|
|
|
|
|
'Basic ${base64.encode(utf8.encode('RegroupUserName:71%@L%es^bUX94`J9XT*@bh,._WWM{\$%^^&&'))}';
|
2024-07-09 14:41:15 +05:30
|
|
|
|
2024-07-11 17:15:41 +05:30
|
|
|
Future<ResponseData> getApi(String url, {bool optionalpar = false}) async {
|
2024-05-23 15:43:13 +05:30
|
|
|
if (kDebugMode) {
|
|
|
|
|
print("api url is >>> $url");
|
|
|
|
|
}
|
|
|
|
|
Response response;
|
|
|
|
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
2024-07-12 19:12:43 +05:30
|
|
|
token = prefs.getString('access-token');
|
2024-07-11 17:15:41 +05:30
|
|
|
log(token.toString());
|
2024-05-23 15:43:13 +05:30
|
|
|
|
|
|
|
|
try {
|
2024-07-11 17:15:41 +05:30
|
|
|
response = await dio.get(
|
|
|
|
|
url,
|
|
|
|
|
options:
|
|
|
|
|
// Options(headers: {
|
|
|
|
|
// "authorization": "Bearer $token",
|
|
|
|
|
// 'content-Type': 'application/json',
|
|
|
|
|
// })
|
|
|
|
|
optionalpar
|
|
|
|
|
? Options(
|
|
|
|
|
headers: {
|
|
|
|
|
"authorization": basicAuth,
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
: Options(
|
|
|
|
|
headers: {
|
|
|
|
|
'authorization': basicAuth,
|
2024-08-14 13:49:57 +05:30
|
|
|
'access-token':
|
|
|
|
|
token
|
2024-07-11 17:15:41 +05:30
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
);
|
2024-08-14 13:49:57 +05:30
|
|
|
}
|
|
|
|
|
on Exception catch (e) {
|
|
|
|
|
// log(e.toString());
|
|
|
|
|
if (e is DioException) {
|
|
|
|
|
log(e.response.toString());
|
|
|
|
|
if (e.response == null) {
|
|
|
|
|
return ResponseData<dynamic>(
|
|
|
|
|
'Oops something Went Wrong, Please try again!',
|
|
|
|
|
ResponseStatus.FAILED,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if (e.response!.statusCode == 401) {
|
|
|
|
|
if (e.response!.data['message'] == 'Invalid token') {
|
|
|
|
|
// prefs.remove('access-token');
|
|
|
|
|
// await prefs.clear();
|
|
|
|
|
// Get.offNamed(RouteName.loginScreen);
|
|
|
|
|
utils.showToast('Please login again');
|
|
|
|
|
} else {
|
|
|
|
|
return ResponseData<dynamic>(
|
|
|
|
|
'Oops something Went Wrong, Please try again!',
|
|
|
|
|
ResponseStatus.FAILED,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
if (e.response!.statusCode == 403) {
|
|
|
|
|
if (e.response!.data['message'] is List) {
|
|
|
|
|
return ResponseData<dynamic>(
|
|
|
|
|
e.response!.data['message'][0]!, ResponseStatus.FAILED,
|
|
|
|
|
data: e.response!.data);
|
|
|
|
|
} else {
|
|
|
|
|
return ResponseData<dynamic>(
|
|
|
|
|
e.response!.data['message'], ResponseStatus.FAILED,
|
|
|
|
|
data: e.response!.data);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-23 15:43:13 +05:30
|
|
|
return ResponseData<dynamic>(
|
|
|
|
|
'Oops something Went Wrong', ResponseStatus.FAILED);
|
|
|
|
|
}
|
2024-07-11 17:15:41 +05:30
|
|
|
// on Exception catch (e) {
|
|
|
|
|
// if (e is DioException) {
|
|
|
|
|
// if (e.response!.statusCode == 403) {
|
|
|
|
|
// return ResponseData<dynamic>(
|
|
|
|
|
// e.response!.data['message'][0]!, ResponseStatus.FAILED,
|
|
|
|
|
// data: e.response!.data);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// return ResponseData<dynamic>(
|
|
|
|
|
// 'Oops something Went Wrong',
|
|
|
|
|
// ResponseStatus.FAILED,
|
|
|
|
|
// );
|
|
|
|
|
// }
|
2024-05-23 15:43:13 +05:30
|
|
|
if (response.statusCode == 200) {
|
|
|
|
|
return ResponseData<dynamic>("success", ResponseStatus.SUCCESS,
|
|
|
|
|
data: response.data);
|
2024-07-17 17:20:01 +05:30
|
|
|
} else if (response.statusCode == 201) {
|
|
|
|
|
return ResponseData<dynamic>("success", ResponseStatus.SUCCESS,
|
|
|
|
|
data: response.data);
|
2024-05-23 15:43:13 +05:30
|
|
|
} else if (response.statusCode == 404) {
|
|
|
|
|
return ResponseData<dynamic>("error", ResponseStatus.ERROR,
|
|
|
|
|
data: response.data);
|
|
|
|
|
} else {
|
|
|
|
|
try {
|
|
|
|
|
return ResponseData<dynamic>(
|
|
|
|
|
response.data['message'].toString(), ResponseStatus.FAILED);
|
|
|
|
|
} catch (_) {
|
|
|
|
|
return ResponseData<dynamic>(
|
|
|
|
|
response.statusMessage!, ResponseStatus.FAILED);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-09 14:41:15 +05:30
|
|
|
// Future<ResponseData> postApi(
|
|
|
|
|
// data,
|
|
|
|
|
// String url,
|
|
|
|
|
// {bool optionalpar = false}
|
|
|
|
|
// ) async {
|
|
|
|
|
// if (kDebugMode) {
|
|
|
|
|
// print("data >>> $data");
|
|
|
|
|
// print("api url is >>> $url");
|
|
|
|
|
// }
|
|
|
|
|
// Response response;
|
|
|
|
|
// SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
|
|
|
// // ignore: unused_local_variable
|
|
|
|
|
// String? token = prefs.getString('token').toString();
|
|
|
|
|
// print("token is $token");
|
|
|
|
|
// log(token.toString());
|
|
|
|
|
// try {
|
|
|
|
|
// response = await dio.post(url,
|
|
|
|
|
// data: data,
|
2024-07-10 15:02:09 +05:30
|
|
|
// options: optionalpar
|
2024-07-09 14:41:15 +05:30
|
|
|
// ?
|
|
|
|
|
// Options(
|
|
|
|
|
// headers: {
|
|
|
|
|
// "authorization": basicAuth,
|
|
|
|
|
// },
|
|
|
|
|
// )
|
|
|
|
|
// :
|
|
|
|
|
// Options(
|
|
|
|
|
// headers: {'authorization': basicAuth, 'access-token': token},
|
|
|
|
|
// ),
|
|
|
|
|
// );
|
|
|
|
|
// log(response.toString());
|
|
|
|
|
// } on Exception catch (e) {
|
|
|
|
|
// if (e is DioException) {
|
|
|
|
|
// log(e.response.toString());
|
|
|
|
|
// }
|
|
|
|
|
// return ResponseData<dynamic>(
|
|
|
|
|
// 'Opps something went wrong', ResponseStatus.FAILED);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// // if (kDebugMode) {
|
|
|
|
|
// // print(response);
|
|
|
|
|
// // }
|
|
|
|
|
|
|
|
|
|
// // print("response in post $response");
|
|
|
|
|
|
|
|
|
|
// if (response.statusCode == 200) {
|
|
|
|
|
// // print(response.data);
|
|
|
|
|
|
|
|
|
|
// return ResponseData<dynamic>("success", ResponseStatus.SUCCESS,
|
|
|
|
|
// data: response.data);
|
|
|
|
|
// } else {
|
|
|
|
|
// try {
|
|
|
|
|
// return ResponseData<dynamic>(
|
|
|
|
|
// response.data['message'].toString(), ResponseStatus.FAILED);
|
|
|
|
|
// } catch (_) {
|
|
|
|
|
// return ResponseData<dynamic>(
|
|
|
|
|
// response.statusMessage!, ResponseStatus.FAILED);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
//New post api
|
|
|
|
|
|
2024-07-11 17:15:41 +05:30
|
|
|
@override
|
2024-07-09 14:41:15 +05:30
|
|
|
Future<ResponseData> postApi(data, String url,
|
|
|
|
|
{bool optionalpar = false}) async {
|
2024-05-23 15:43:13 +05:30
|
|
|
if (kDebugMode) {
|
|
|
|
|
print("data >>> $data");
|
|
|
|
|
print("api url is >>> $url");
|
|
|
|
|
}
|
|
|
|
|
Response response;
|
2024-07-09 14:41:15 +05:30
|
|
|
|
2024-05-23 15:43:13 +05:30
|
|
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
2024-07-10 15:02:09 +05:30
|
|
|
String? token = prefs.getString('access-token');
|
2024-07-12 11:26:57 +05:30
|
|
|
|
2024-05-23 15:43:13 +05:30
|
|
|
try {
|
2024-07-09 14:46:28 +05:30
|
|
|
response = await dio.post(
|
|
|
|
|
url,
|
|
|
|
|
data: data,
|
2024-07-09 14:41:15 +05:30
|
|
|
options: optionalpar
|
2024-07-11 20:01:38 +05:30
|
|
|
// (token != null)
|
2024-07-09 14:46:28 +05:30
|
|
|
? Options(
|
|
|
|
|
headers: {
|
|
|
|
|
"authorization": basicAuth,
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
: Options(
|
2024-08-14 13:49:57 +05:30
|
|
|
headers: {'authorization': basicAuth, 'access-token':
|
|
|
|
|
token
|
|
|
|
|
},
|
2024-07-09 14:46:28 +05:30
|
|
|
),
|
|
|
|
|
);
|
2024-07-09 14:41:15 +05:30
|
|
|
log(response.toString());
|
2024-05-23 15:43:13 +05:30
|
|
|
} on Exception catch (e) {
|
|
|
|
|
if (e is DioException) {
|
2024-07-10 15:02:09 +05:30
|
|
|
log(e.response.toString());
|
|
|
|
|
if (e.response == null) {
|
|
|
|
|
return ResponseData<dynamic>(
|
|
|
|
|
'Oops something Went Wrong, Please try again!',
|
|
|
|
|
ResponseStatus.FAILED,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if (e.response!.statusCode == 401) {
|
2024-08-14 13:49:57 +05:30
|
|
|
if (e.response!.data['message'] == 'Invalid token') {
|
|
|
|
|
prefs.remove('access-token');
|
|
|
|
|
await prefs.clear();
|
|
|
|
|
Get.offNamed(RouteName.loginScreen);
|
|
|
|
|
utils.showToast('Please login again');
|
|
|
|
|
} else {
|
|
|
|
|
return ResponseData<dynamic>(
|
|
|
|
|
'Oops something Went Wrong, Please try again!',
|
|
|
|
|
ResponseStatus.FAILED,
|
|
|
|
|
);
|
|
|
|
|
}
|
2024-07-10 15:02:09 +05:30
|
|
|
// Get.toNamed(RouteName.login);
|
2024-08-14 13:49:57 +05:30
|
|
|
// return ResponseData<dynamic>(
|
|
|
|
|
// 'Oops something Went Wrong, Please try again!',
|
|
|
|
|
// ResponseStatus.FAILED,
|
|
|
|
|
// );
|
2024-07-10 15:02:09 +05:30
|
|
|
}
|
2024-07-09 14:41:15 +05:30
|
|
|
if (e.response!.statusCode == 403) {
|
2024-07-11 17:15:41 +05:30
|
|
|
if (e.response!.data['message'] is List) {
|
|
|
|
|
return ResponseData<dynamic>(
|
|
|
|
|
e.response!.data['message'][0]!, ResponseStatus.FAILED,
|
|
|
|
|
data: e.response!.data);
|
|
|
|
|
} else {
|
|
|
|
|
return ResponseData<dynamic>(
|
|
|
|
|
e.response!.data['message'], ResponseStatus.FAILED,
|
|
|
|
|
data: e.response!.data);
|
|
|
|
|
}
|
2024-07-09 14:41:15 +05:30
|
|
|
}
|
2024-05-23 15:43:13 +05:30
|
|
|
}
|
|
|
|
|
return ResponseData<dynamic>(
|
2024-07-09 14:41:15 +05:30
|
|
|
'Oops something Went Wrong',
|
|
|
|
|
ResponseStatus.FAILED,
|
|
|
|
|
);
|
2024-05-23 15:43:13 +05:30
|
|
|
}
|
|
|
|
|
|
2024-07-10 15:02:09 +05:30
|
|
|
if (response.statusCode == 200 || response.statusCode == 201) {
|
2024-07-09 14:41:15 +05:30
|
|
|
return ResponseData<dynamic>("success", ResponseStatus.SUCCESS,
|
|
|
|
|
data: response.data);
|
|
|
|
|
} else if (response.statusCode == 203) {
|
|
|
|
|
print(response.data);
|
|
|
|
|
return ResponseData<dynamic>("success", ResponseStatus.PRIVATE,
|
|
|
|
|
data: response.data);
|
2024-05-23 15:43:13 +05:30
|
|
|
} else {
|
|
|
|
|
try {
|
|
|
|
|
return ResponseData<dynamic>(
|
|
|
|
|
response.data['message'].toString(), ResponseStatus.FAILED);
|
|
|
|
|
} catch (_) {
|
|
|
|
|
return ResponseData<dynamic>(
|
|
|
|
|
response.statusMessage!, ResponseStatus.FAILED);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<ResponseData> postFileUploadApi({data, required String url}) async {
|
|
|
|
|
if (kDebugMode) {
|
|
|
|
|
print("data >>> $data");
|
|
|
|
|
print("api url is >>> $url");
|
|
|
|
|
}
|
|
|
|
|
Response response;
|
|
|
|
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
|
|
|
// ignore: unused_local_variable
|
2024-07-12 12:46:49 +05:30
|
|
|
String? token = prefs.getString('access-token').toString();
|
2024-05-23 15:43:13 +05:30
|
|
|
try {
|
|
|
|
|
response = await dio.post(url,
|
|
|
|
|
data: data,
|
|
|
|
|
options: Options(headers: {"authorization": "Bearer $token"}));
|
|
|
|
|
} on Exception catch (_) {
|
|
|
|
|
return ResponseData<dynamic>(
|
|
|
|
|
'Opps something went wrong', ResponseStatus.FAILED);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (kDebugMode) {
|
|
|
|
|
print(response);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
print("response in post $response");
|
|
|
|
|
|
|
|
|
|
if (response.statusCode == 200) {
|
|
|
|
|
// print(response.data);
|
|
|
|
|
|
|
|
|
|
return ResponseData<dynamic>("success", ResponseStatus.SUCCESS,
|
|
|
|
|
data: response.data);
|
|
|
|
|
} else {
|
|
|
|
|
try {
|
|
|
|
|
return ResponseData<dynamic>(
|
|
|
|
|
response.data['message'].toString(), ResponseStatus.FAILED);
|
|
|
|
|
} catch (_) {
|
|
|
|
|
return ResponseData<dynamic>(
|
|
|
|
|
response.statusMessage!, ResponseStatus.FAILED);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<ResponseData<dynamic>> postApiHttp(
|
|
|
|
|
String token, String url, Map<String, String> body) async {
|
|
|
|
|
// var headers = {
|
|
|
|
|
// 'Authorization': 'Bearer 1867|aBb92qswYsEzQa8LJayiuQw6B3Wofuj6iluUumLx',
|
|
|
|
|
// 'Authorization': 'Bearer 189|yeRLynwInflhfnVObT7dd7R0Ywv91AIlxIKXoiAv',
|
|
|
|
|
// 'Cookie': 'laravel_session=eyJpdiI6ImcwS2NYNlJYam4wcU1YUXJsYWZsb2c9PSIsInZhbHVlIjoiK0hvT3c5NmZFQ0NDajYxTUFaaVluWkpYbUkwYk1JbldyTVJwZitMN05zWnliaVdBNWZjTXpyVG5UODM1MTBaMzQwUCtNc3lGak5MQWRZamh2dWIvdzIxQnNVVWQrQi9NUi9YTS9PQWgxMlZHTENUNU0zY0VVazluNEplTFFvbGgiLCJtYWMiOiJkNjA0NjA4YWJhZDkxODA0YmQ2MTViNzc1MTg4OWRiODMzMjI5OGE0ZDI3MDRhMTAzM2E1MGY4ODQyMjI1NGIxIiwidGFnIjoiIn0%3D'
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
// controllerEntryPoint.logedIn!
|
|
|
|
|
// ?
|
|
|
|
|
// headers = {"authorization": "Bearer $token"};
|
|
|
|
|
// : headers = {
|
|
|
|
|
// "authorization":
|
|
|
|
|
// "Bearer 189|yeRLynwInflhfnVObT7dd7R0Ywv91AIlxIKXoiAv"
|
|
|
|
|
// };
|
|
|
|
|
var headers = {
|
|
|
|
|
'Accept': 'application/json',
|
|
|
|
|
'Authorization': token,
|
|
|
|
|
// 'Cookie': 'jerichoalternatives_session=eyJpdiI6Ik5KTWVUUnM2elR0b0Z0SWZneWY2Nmc9PSIsInZhbHVlIjoiY0s5WjV5UmJyZ3J2UUY1enY4KzZEblg5RmxWUm1KdXpmVWxQVTRKNUgyMThqRlJPK1lrcVhXMzJLMkhjSW5BdFJhNEgyTWFZQmM3Sll0aG52d1F4RGpSM0l4TlFWWlVPaUhpVFVsQ3lnaW8rSXJSY2Y2aG8ydFhqck8xTmlDaUMiLCJtYWMiOiI2MmNhZWZjYmZkMzBlYzhhZjcxNzRhMmM1OGJhYmRjM2JkOGMzM2Y3ZGFmMWViNWIyOTYyODY5ZDk3MmZmNGI3IiwidGFnIjoiIn0%3D'
|
|
|
|
|
};
|
|
|
|
|
var request = http.MultipartRequest('POST', Uri.parse(url));
|
|
|
|
|
|
|
|
|
|
request.fields.addAll(body);
|
|
|
|
|
|
|
|
|
|
request.headers.addAll(headers);
|
|
|
|
|
|
|
|
|
|
http.StreamedResponse response = await request.send();
|
|
|
|
|
|
|
|
|
|
print(response.statusCode);
|
|
|
|
|
|
|
|
|
|
if (response.statusCode == 200) {
|
|
|
|
|
var resp = await response.stream.bytesToString();
|
|
|
|
|
var jsonResp = jsonDecode(resp);
|
|
|
|
|
print(jsonResp);
|
|
|
|
|
return ResponseData<dynamic>("success", ResponseStatus.SUCCESS,
|
|
|
|
|
data: jsonResp);
|
|
|
|
|
// return await response.stream.bytesToString();
|
|
|
|
|
} else if (response.statusCode == 201) {
|
|
|
|
|
var resp = await response.stream.bytesToString();
|
|
|
|
|
var jsonResp = jsonDecode(resp);
|
|
|
|
|
print(jsonResp);
|
|
|
|
|
return ResponseData<dynamic>(jsonResp["message"], ResponseStatus.PRIVATE,
|
|
|
|
|
data: jsonResp);
|
|
|
|
|
} else if (response.statusCode == 400) {
|
|
|
|
|
var resp = await response.stream.bytesToString();
|
|
|
|
|
var jsonResp = jsonDecode(resp);
|
|
|
|
|
print(jsonResp);
|
|
|
|
|
return ResponseData<dynamic>(
|
|
|
|
|
jsonResp["message"],
|
|
|
|
|
ResponseStatus.FAILED,
|
|
|
|
|
);
|
|
|
|
|
} else if (response.statusCode == 422) {
|
|
|
|
|
var resp = await response.stream.bytesToString();
|
|
|
|
|
var jsonResp = jsonDecode(resp);
|
|
|
|
|
print(jsonResp);
|
2024-07-09 14:46:28 +05:30
|
|
|
var errorMessage = jsonResp["errors"]["email2"].join(", ") +
|
|
|
|
|
"\n" +
|
|
|
|
|
jsonResp["errors"]["contact_number2"].join(", ");
|
2024-05-23 15:43:13 +05:30
|
|
|
// return ResponseData<dynamic>(
|
|
|
|
|
// jsonResp["errors"][0]["email2"] +
|
|
|
|
|
// jsonResp["errors"][0]["contact_number2"],
|
|
|
|
|
// ResponseStatus.PRIVATE,
|
|
|
|
|
// );
|
2024-07-09 14:46:28 +05:30
|
|
|
return ResponseData<String>(
|
|
|
|
|
errorMessage,
|
|
|
|
|
ResponseStatus.PRIVATE,
|
|
|
|
|
);
|
2024-05-23 15:43:13 +05:30
|
|
|
} else if (response.statusCode == 500) {
|
|
|
|
|
var resp = await response.stream.bytesToString();
|
|
|
|
|
var jsonResp = jsonDecode(resp);
|
|
|
|
|
print(jsonResp);
|
|
|
|
|
return ResponseData<dynamic>(
|
|
|
|
|
jsonResp["message"],
|
|
|
|
|
ResponseStatus.FAILED,
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
return ResponseData<dynamic>(
|
|
|
|
|
response.reasonPhrase!,
|
|
|
|
|
ResponseStatus.FAILED,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<ResponseData> postslugApi(String url) async {
|
|
|
|
|
if (kDebugMode) {
|
|
|
|
|
print("api url is >>> $url");
|
|
|
|
|
}
|
|
|
|
|
Response response;
|
|
|
|
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
|
|
|
// String? token = prefs.getString('token');
|
2024-07-12 12:46:49 +05:30
|
|
|
String? token = prefs.getString('access-token').toString();
|
2024-05-23 15:43:13 +05:30
|
|
|
print("token is $token");
|
|
|
|
|
try {
|
|
|
|
|
response = await dio.post(url,
|
|
|
|
|
options: Options(headers: {"authorization": "Bearer $token"}));
|
|
|
|
|
} on Exception catch (_) {
|
|
|
|
|
return ResponseData<dynamic>(
|
|
|
|
|
'Oops something Went Wrong', ResponseStatus.FAILED);
|
|
|
|
|
}
|
|
|
|
|
if (response.statusCode == 200) {
|
|
|
|
|
return ResponseData<dynamic>("success", ResponseStatus.SUCCESS,
|
|
|
|
|
data: response.data);
|
|
|
|
|
} else {
|
|
|
|
|
try {
|
|
|
|
|
return ResponseData<dynamic>(
|
|
|
|
|
response.data['message'].toString(), ResponseStatus.FAILED);
|
|
|
|
|
} catch (_) {
|
|
|
|
|
return ResponseData<dynamic>(
|
|
|
|
|
response.statusMessage!, ResponseStatus.FAILED);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|