2021-01-06 17:35:57 +00:00
|
|
|
import 'package:dio/dio.dart';
|
2021-01-14 21:48:05 +00:00
|
|
|
import 'package:selfprivacy/config/get_it_config.dart';
|
|
|
|
import 'package:selfprivacy/logic/get_it/console.dart';
|
|
|
|
import 'package:selfprivacy/logic/models/message.dart';
|
2021-01-06 17:35:57 +00:00
|
|
|
|
|
|
|
abstract class ApiMap {
|
|
|
|
String rootAddress;
|
|
|
|
|
2021-01-14 21:48:05 +00:00
|
|
|
// Dio client = Dio();
|
|
|
|
|
|
|
|
Dio loggedClient = Dio()..interceptors.add(ConsoleInterceptor());
|
2021-01-06 17:35:57 +00:00
|
|
|
|
|
|
|
void close() {
|
2021-01-14 21:48:05 +00:00
|
|
|
loggedClient.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class ConsoleInterceptor extends InterceptorsWrapper {
|
|
|
|
void addMessage(Message message) {
|
|
|
|
getIt.get<ConsoleModel>().addMessage(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Future onRequest(RequestOptions options) async {
|
|
|
|
addMessage(
|
|
|
|
Message(
|
|
|
|
text:
|
|
|
|
'request-uri: ${options.uri}\nheaders: ${options.headers}\ndata: ${options.data}',
|
|
|
|
),
|
|
|
|
);
|
|
|
|
return super.onRequest(options);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Future onResponse(Response response) async {
|
|
|
|
addMessage(
|
|
|
|
Message(
|
|
|
|
text:
|
|
|
|
'response-uri: ${response.request.uri}\ncode: ${response.statusCode}\n',
|
|
|
|
),
|
|
|
|
);
|
|
|
|
return super.onResponse(response);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Future onError(DioError err) async {
|
|
|
|
return super.onError(err);
|
2021-01-06 17:35:57 +00:00
|
|
|
}
|
|
|
|
}
|