2023-03-30 07:34:12 +00:00
|
|
|
import 'package:dio/dio.dart';
|
|
|
|
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
|
|
|
|
2023-05-18 08:04:03 +00:00
|
|
|
import '../app/app.logger.dart';
|
|
|
|
|
2023-03-30 07:34:12 +00:00
|
|
|
class MyHttpServices {
|
2023-05-18 08:04:03 +00:00
|
|
|
final log = getLogger('MyHttpServices');
|
2023-03-30 07:34:12 +00:00
|
|
|
final _options = BaseOptions(
|
|
|
|
baseUrl: dotenv.env['api_url']!,
|
2023-05-18 10:58:21 +00:00
|
|
|
connectTimeout: const Duration(seconds: 120),
|
|
|
|
receiveTimeout: const Duration(seconds: 120),
|
2023-03-30 07:34:12 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
late Dio _dio;
|
|
|
|
|
|
|
|
MyHttpServices() {
|
|
|
|
_dio = Dio(_options);
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<Response> get(String path) async {
|
|
|
|
try {
|
|
|
|
return await _dio.get(path);
|
2023-08-20 19:46:54 +00:00
|
|
|
} on DioError catch (e) {
|
|
|
|
log.e(e.message);
|
|
|
|
log.e(e.response);
|
2023-03-30 07:34:12 +00:00
|
|
|
rethrow;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<Response> postWithFormData(String path, FormData formData) async {
|
|
|
|
try {
|
|
|
|
return await _dio.post(path, data: formData);
|
2023-08-20 19:46:54 +00:00
|
|
|
} on DioError catch (e) {
|
|
|
|
log.e(e.message);
|
2024-06-05 09:09:58 +00:00
|
|
|
log.e(e.response!.statusCode);
|
|
|
|
log.e(e.response!.statusMessage);
|
2023-03-30 07:34:12 +00:00
|
|
|
rethrow;
|
|
|
|
}
|
|
|
|
}
|
2023-08-20 19:46:54 +00:00
|
|
|
|
|
|
|
// // delete
|
|
|
|
// Future<Response> delete(String path, FormData data) async {
|
|
|
|
// try {
|
|
|
|
// // log.i('path: $path');
|
|
|
|
// return await _dio.delete(
|
|
|
|
// path,
|
|
|
|
// data: data,
|
|
|
|
// // encoding: Encoding.getByName('utf-8'),
|
|
|
|
// options: Options(
|
|
|
|
// headers: {
|
|
|
|
// 'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
// },
|
|
|
|
// ),
|
|
|
|
// );
|
|
|
|
// } on DioError catch (e) {
|
|
|
|
// log.e(e.message);
|
|
|
|
// log.e(e.response);
|
|
|
|
// rethrow;
|
|
|
|
// }
|
|
|
|
// }
|
2023-03-30 07:34:12 +00:00
|
|
|
}
|