Files
Prod/lib/models/editor.dart
Phani Pavan K 73827ea62c
Some checks failed
Build CI / Build (push) Has been cancelled
first working prototype
2026-02-11 22:59:48 +05:30

52 lines
1.3 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 name;
final String command;
final String commandTemplate;
// final Icon icon;
const Editor(this.name, this.command, this.commandTemplate, this.id);
factory Editor.create(String name, String command, String commandTemplate) {
return Editor(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 {
"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")) {
print("Found invalid editor config when parsing: $data");
return Editor("null", "null", "null", "null");
}
return Editor(
data["name"] as String,
data["command"] as String,
data["commandTemplate"] as String,
data["id"] as String,
);
}
}