loadFromAsset method

Future<void> loadFromAsset(
  1. String assetPath, {
  2. bool removeEnvSubst = true,
})

Implementation

Future<void> loadFromAsset(
  final String assetPath, {
  final bool removeEnvSubst = true,
}) async {
  configJson.clear();

  try {
    String configString = await DefaultAssetBundle.of(
      context,
    ).loadString(assetPath);

    Map<String, dynamic> localConfig = json.decode(configString);

    if (removeEnvSubst) {
      localConfig.removeWhere(
        (final String key, final dynamic value) =>
            value.toString().startsWith(r'${'),
      );
    }

    configJson.addAll(localConfig);
  } on Exception catch (e, s) {
    if (kDebugMode) {
      print(e);
      print(s);
    }
  }
}