get country api
This commit is contained in:
@@ -1,17 +1,38 @@
|
||||
// common_api.dart
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import '../../Api_Helper/base_manager.dart';
|
||||
|
||||
class NetworkApiService {
|
||||
final Dio _dio = Dio();
|
||||
|
||||
// Common function for GET requests
|
||||
Future<Response> get(String url,
|
||||
Future<ResponseData> get(String url,
|
||||
{Map<String, dynamic>? queryParameters}) async {
|
||||
if (kDebugMode) {
|
||||
print("api url is >>> $url");
|
||||
}
|
||||
Response response;
|
||||
try {
|
||||
return await _dio.get(url);
|
||||
response = await _dio.get(url);
|
||||
if (response.statusCode == 201 || 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>(
|
||||
data: response.data,
|
||||
response.statusMessage!,
|
||||
ResponseStatus.FAILED);
|
||||
}}
|
||||
} catch (e) {
|
||||
throw _handleError(e);
|
||||
return ResponseData<dynamic>(
|
||||
"Something went wrong", ResponseStatus.FAILED);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user