buildJson method
JsonModel?
buildJson(
- File file
)
Implementation
JsonModel? buildJson(File file) {
// json文件不存在 ,返回 null
if (!FileSystemEntity.isFileSync(file.path)) return null;
List<String> paths = path.basename(file.path).split(".");
String name = paths.first;
// 文件不为 .json 格式 , 返回 null
// 文件名以 _ 开头 ,返回 null
if (paths.last.toLowerCase() != "json" || name.startsWith("_")) return null;
JsonModel jsonModel = JsonModel(
srcPath: file.path,
distPath: file.path
.replaceFirst(srcDir, distDir)
.replaceFirst(".json", ".dart"),
export: file.path
.replaceFirst(srcDir + path.separator, "")
.replaceFirst(".json", ".dart"),
fileName: name,
className: name.toBigHump,
);
print("========111");
Map<String, dynamic> jsonMap = json.decode(file.readAsStringSync());
print("========222");
JsonPlugins.getInstance().build(jsonMap, jsonModel);
return jsonModel;
}