writeListToFile method
Writes the enum-like class to a file.
entities
is a list of image file entities to be processed.
Implementation
Future<void> writeListToFile(List<FileSystemEntity> entities) async {
String generatedFilePath = config.classFolderPath;
Directory current = Directory.current;
String fullDirectoryPath = '${current.path}/$generatedFilePath';
await Directory(fullDirectoryPath).create(recursive: true);
String fullFilePath = '$fullDirectoryPath/image_enum_list.dart';
File file = await File(fullFilePath).create(recursive: true);
String content = "class ${config.customClassName} {\n";
content += " ${config.customClassName}._();\n";
entities.sort((a, b) => a.toString().compareTo(b.toString()));
for (var entity in entities) {
final String assetName = p.basenameWithoutExtension(entity.path);
final String camelCaseAssetName = assetName.toCamelCase;
final String asset =
" static String get $camelCaseAssetName => '$assetName';\n";
content += asset;
}
content += "}";
await file.writeAsString(content);
print('File image_enum_list_generator.dart successfully created.');
}