buildJson method Null safety

JsonModel? buildJson(
  1. 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,
  );
  Map<String, dynamic> jsonMap = json.decode(file.readAsStringSync());
  JsonPlugins.getInstance().build(jsonMap, jsonModel);
  return jsonModel;
}