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);
|
|
|
|
} on DioError {
|
|
|
|
rethrow;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<Response> postWithFormData(String path, FormData formData) async {
|
|
|
|
try {
|
|
|
|
return await _dio.post(path, data: formData);
|
|
|
|
} on DioError {
|
|
|
|
rethrow;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|