Removal of api key

Network calls,
integration of retrofit api
added backup api
This commit is contained in:
2022-09-19 22:13:37 +01:00
parent 5104fc674e
commit 8cc19f0dc9
16 changed files with 548 additions and 12 deletions

View File

@@ -0,0 +1,30 @@
import 'dart:io';
import 'package:dio/dio.dart';
import 'package:retrofit/retrofit.dart';
import '../../main.dart';
mixin SafeApiCall {
Future<T> getDataFromApiCall<T>(Future<HttpResponse<T>> apiCall) async {
try {
HttpResponse<T> httpResponse = await apiCall;
return httpResponse.data;
} on DioError catch(dioError) {
Map<String, dynamic>? errorResponse = dioError.response?.data;
String error;
if (errorResponse?["error"] != null){
error = errorResponse!["error"];
} else if (dioError.error != null){
error = dioError.error;
} else {
error = "Failed to retrieve data from api";
}
logger.e(dioError.error);
throw HttpException(error);
}
}
}