Token management, Factory reset, UX/UI Improvements
This commit is contained in:
+22
-7
@@ -1,17 +1,32 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:dio/io.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:http/io_client.dart';
|
||||
|
||||
Future<http.Client> createEspHttpClient() async {
|
||||
Future<Dio> createEspHttpClient({String token = ""}) async {
|
||||
Dio dio = Dio();
|
||||
|
||||
final certData = await rootBundle.load("assets/certificates/rootCA.crt");
|
||||
final certBytes = certData.buffer.asUint8List();
|
||||
|
||||
SecurityContext securityContext = SecurityContext.defaultContext;
|
||||
securityContext.setTrustedCertificatesBytes(certBytes);
|
||||
dio.httpClientAdapter = IOHttpClientAdapter(
|
||||
createHttpClient: () {
|
||||
SecurityContext securityContext = SecurityContext.defaultContext;
|
||||
securityContext.setTrustedCertificatesBytes(certBytes);
|
||||
|
||||
HttpClient client = HttpClient(context: securityContext);
|
||||
return HttpClient(context: securityContext);
|
||||
}
|
||||
);
|
||||
|
||||
return IOClient(client);
|
||||
if (token.isNotEmpty) {
|
||||
dio.interceptors.add(InterceptorsWrapper(onRequest: (RequestOptions options, RequestInterceptorHandler handler) {
|
||||
options.headers.addAll({
|
||||
"Authorization": "Bearer $token"
|
||||
});
|
||||
return handler.next(options);
|
||||
}));
|
||||
}
|
||||
|
||||
return dio;
|
||||
}
|
||||
Reference in New Issue
Block a user