Files
Prod/lib/models/editor.dart
Phani Pavan K ec3e69ffa9
All checks were successful
Build CI / AMD64 Build (push) Successful in 3m23s
Build CI / ARM64 Build (push) Successful in 7m16s
added prj editing page, must change to dialog bcz page too big
2026-02-15 19:06:15 +05:30

67 lines
1.5 KiB
Dart

import "package:flutter/material.dart";
import "package:process_run/which.dart";
import "package:prod/models/rand.dart";
class Editor {
final String id;
final String sname;
final String name;
final String command;
final String commandTemplate;
const Editor(
this.sname,
this.name,
this.command,
this.commandTemplate,
this.id,
);
factory Editor.create(String name, String command, String commandTemplate) {
return Editor(
"${name.substring(0, 1).toUpperCase()}${name.substring(1, 2).toLowerCase()}",
name,
command,
commandTemplate,
getRandomString(5),
);
}
bool validateCommand() {
final String? fullPath = whichSync(command);
if (fullPath == null) {
return false;
} else {
return true;
}
}
Map<String, dynamic> toJson() {
return {
"sname": sname,
"name": name,
"command": command,
"commandTemplate": commandTemplate,
"id": id,
};
}
factory Editor.fromJson(Map<String, dynamic> data) {
if (!data.containsKey("name") ||
!data.containsKey("command") ||
!data.containsKey("commandTemplate") ||
!data.containsKey("id") ||
!data.containsKey("sname")) {
print("Found invalid editor config when parsing: $data");
return Editor("!!", "null", "null", "null", "null");
}
return Editor(
data["sname"] as String,
data["name"] as String,
data["command"] as String,
data["commandTemplate"] as String,
data["id"] as String,
);
}
}