// common_api.dart import 'package:dio/dio.dart'; class NetworkApiService { final Dio _dio = Dio(); // Common function for GET requests Future get(String url, {Map? queryParameters}) async { try { return await _dio.get(url); } catch (e) { throw _handleError(e); } } // Common function for POST requests Future post(String url, dynamic data) async { try { return await _dio.post(url, data: data); } catch (e) { throw _handleError(e); } } // Common function for PUT requests Future put(String url, dynamic data) async { try { return await _dio.put(url, data: data); } catch (e) { throw _handleError(e); } } // Common function for DELETE requests Future delete(String url) async { try { return await _dio.delete(url); } catch (e) { throw _handleError(e); } } // Handle Dio errors dynamic _handleError(dynamic e) { if (e is DioException) { // Handle Dio specific errors (e.g., DioErrorType.connectTimeout, DioErrorType.response) return e.message; // Or return a custom error message } else { return 'An error occurred'; // Generic error message for other types of errors } } }