loadAsset method

Future<void> loadAsset()

Implementation

Future<void> loadAsset(/*BuildContext context*/) async {
  String cipherString = '';
  try {
    cipherString =
        await rootBundle.loadString('assets/${enterprise}_config.json');
    //jsonString = await DefaultAssetBundle.of(context).loadString('assets/${enterprise}_config.json');
    logger.info('assets/${enterprise}_config.json loaded');
  } catch (e) {
    logger.info(
        'assets/${enterprise}_config.json not exist, hycop_config.json will be used');
    try {
      cipherString = await rootBundle.loadString('assets/hycop_config.json');
      //jsonString = await DefaultAssetBundle.of(context).loadString('assets/hycop_config.json');
      logger.info('assets/hycop_config.json loaded');
    } catch (e) {
      logger.severe('load assets/hycop_config.json failed', e);
      return;
    }
  }
  //logger.finest(cipherString);
  String jsonString = await MyEncrypt.toDecrypt(cipherString);
  //logger.finest(jsonString);
  jsonMap = jsonDecode(jsonString);

  final dynamic configMap = jsonMap['AssetConfig'];
  _savePeriod = configMap['savePeriod'] ?? 1000;
  _apiServerUrl = configMap['apiServerUrl'] ?? 'http://localhost:3000';
  if (_apiServerUrl[_apiServerUrl.length - 1] == '/') {
    _apiServerUrl = _apiServerUrl.substring(0, _apiServerUrl.length - 1);
  }
  _googleOAuthCliendId = configMap['googleOAuthCliendId'] ?? '';
  _guestUserId = configMap['guestUserId'] ?? '';
  _guestUserPassword = configMap['guestUserPassword'] ?? '';
}