getPubspecAsset method

Future<List<String>> getPubspecAsset()

Reads the pubspec.yaml file and returns a list of assets.

Implementation

Future<List<String>> getPubspecAsset() async {
  final pubspecFile = File(_getPubspecPath);
  if (await pubspecFile.exists() == true) {
    final YamlMap map = loadYaml(pubspecFile.readAsStringSync()) as YamlMap;
    final dynamic flutterMap = map['flutter'];
    if (flutterMap is YamlMap) {
      final dynamic assetMap = flutterMap['assets'];
      if (assetMap is YamlList) {
        List<String> assets = _getListFromYamlList(assetMap);
        assets = assets.map((e) => clearFileNameFromPath(e)).toList();
        return assets;
      } else {}
    }
  } else {
    print("[🚫] pubspec.yaml file not found");
  }
  return <String>[];
}