createEntityCode static method
Future<void>
createEntityCode(
{ - required Map map,
- required String targetDir,
- required String entityClassName,
- bool? forceFlush = false,
})
Implementation
static Future<void> createEntityCode({
required Map map,
required String targetDir,
required String entityClassName,
bool? forceFlush = false, //覆盖,慎用
}) async {
bool isDir = await FFDirectory.isExistDirectory(targetDir);
if (isDir == false) {
print("路径不存在,将为你自动创建 ${targetDir}");
}
if (!targetDir.endsWith(Platform.pathSeparator)) {
targetDir = "${targetDir}${Platform.pathSeparator}";
}
String classCode = MyEntityLog.log(entityClassName, map);
String filePath = "$targetDir$entityClassName.dart";
if (forceFlush == true) {
bool success = await FFile.writeContentByPath(filePath: filePath, content: classCode,mode: FileMode.write);
if (success == true) {
print("路径下类覆盖成功 ${filePath}");
} else {
print("路径下类覆盖失败 ${filePath}");
}
} else {
bool exist = await FFile.isExistFile(filePath);
if (exist) {
print("路径下类已经存在 ${filePath}");
} else {
bool success = await FFile.writeContentByPath(filePath: filePath, content: classCode,autoCreate: true);
if (success == true) {
print("路径下类生成成功 ${filePath}");
} else {
print("路径下类生成失败 ${filePath}");
}
}
}
}