initialize method

Future initialize(
  1. BizDocAppState appState
)

Implementation

Future initialize(BizDocAppState appState) async {
  _googleMapsApiKey = appState.googleMaps?.apiKey;
  final systemLocales = PlatformDispatcher.instance.locales.map((element) =>
      element.countryCode != null
          ? '${element.languageCode}-${element.countryCode}'
          : element.languageCode);
  _dio.options.baseUrl = '${appState.serverAddress}api';
  final Map<String, String> headers = {
    HttpHeaders.acceptLanguageHeader: systemLocales.join(', '),
    HttpHeaders.acceptHeader: 'application/json, text/plain, */*',
    'Access-Control-Allow-Origin': '*',
    'Access-Control-Allow-Credentials': 'true',
  };
  if (appState.certificate != null) {
    _certificate = await rootBundle.load(appState.certificate!);
  }
  try {
    _credentials = await appState.authentication.getCredentials();
  } catch (e) {
    print(e);
  }
  if (!kIsWeb)
    (_dio.httpClientAdapter as IOHttpClientAdapter).createHttpClient = () {
      return createHttp(
          _credentials, _certificate, SecurityContext.defaultContext);
    };
  else
    HttpOverrides.global = AppHttpOverrides(_credentials, _certificate);
  try {
    _token = await appState.authentication.getAccessToken();
  } catch (e) {
    print(e);
  }
  if (_token != null) headers['Authorization'] = 'Bearer $_token';
  try {
    final connectionId = await _secureStorage.read(key: 'connectionId');
    if (connectionId != null) headers['connection-id'] = connectionId;
  } catch (e) {
    print(e);
  }
  _dio.options.headers = headers;
  _dio.options.contentType = Headers.jsonContentType;
  if (appState.firebaseSettings != null) {
    await _firebase(appState.firebaseSettings!);
  } else {
    _signalR(appState);
  }
  // _dio.interceptors.add(
  //   LogInterceptor(
  //     logPrint: (o) => debugPrint(o.toString()),
  //   ),
  // );
}