first working prototype
Some checks failed
Build CI / Build (push) Has been cancelled

This commit is contained in:
2026-02-11 22:59:25 +05:30
parent 6a10685033
commit 73827ea62c
13 changed files with 281 additions and 32 deletions

View File

@@ -0,0 +1,2 @@
const String kProjectsKey = "projects";
const String kEditorsKey = "editors";

View File

@@ -1,13 +1,19 @@
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);
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);
@@ -17,4 +23,29 @@ class Editor {
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,
);
}
}

View File

@@ -1,27 +1,75 @@
import 'package:flutter/foundation.dart';
import 'package:prod/models/editor.dart';
import 'package:prod/models/project.dart';
import "package:shared_preferences/shared_preferences.dart";
import "package:prod/models/constants.dart";
// import "package:json_annotation/json_annotation.dart";
import "dart:convert";
class GlobalModel extends ChangeNotifier {
late List<Project> projects;
late List<bool> hoverShow;
late List<Editor> editors;
late SharedPreferences prefs;
bool importedData = false;
GlobalModel() {
projects = [];
editors = [];
hoverShow = List.filled(projects.length, false, growable: true);
SharedPreferences.getInstance().then((a) {
print("Loaded sp");
prefs = a;
if (prefs.containsKey(kProjectsKey)) {
String prjData = prefs.getString(kProjectsKey)!;
List<dynamic> data = jsonDecode(prjData);
projects = [];
for (var d in data) {
projects.add(Project.fromJson(d));
}
} else {
projects = [];
prefs.setString(kProjectsKey, jsonEncode(projects));
}
print(projects);
if (prefs.containsKey(kEditorsKey)) {
String edtData = prefs.getString(kEditorsKey)!;
List<dynamic> data = jsonDecode(edtData);
editors = [];
for (var d in data) {
editors.add(Editor.fromJson(d));
}
} else {
editors = [];
prefs.setString(kEditorsKey, jsonEncode(editors));
}
hoverShow = List.filled(projects.length, false, growable: true);
print("loaded data");
importedData = true;
notifyListeners();
});
}
void saveProjectState() {
var arst = projects.map((a) => a.toJson()).toList();
prefs.setString(kProjectsKey, jsonEncode(arst));
}
void saveEditorState() {
var arst = editors.map((a) => a.toJson()).toList();
prefs.setString(kEditorsKey, jsonEncode(arst));
}
void addPrj(Project prj) {
projects.add(prj);
hoverShow.add(false);
saveProjectState();
notifyListeners();
}
void delPrj(int index) {
projects.removeAt(index);
hoverShow.removeAt(index);
saveProjectState();
notifyListeners();
}
@@ -50,11 +98,13 @@ class GlobalModel extends ChangeNotifier {
void addEdt(Editor edt) {
editors.add(edt);
saveEditorState();
notifyListeners();
}
void delEdt(int index) {
editors.removeAt(index);
saveEditorState();
notifyListeners();
}

View File

@@ -6,7 +6,7 @@ class Project {
final String name;
final String language;
final File path;
final List<Editor> editors;
final List<String> editors;
final bool isGit;
final bool enableTerminal;
@@ -19,14 +19,15 @@ class Project {
this.enableTerminal,
);
factory Project.validated(
factory Project.newValidated(
String name,
String lang,
String path,
List<Editor> editors,
List<String> editors,
bool enableTerminal,
) {
final File fpath = File(path);
print(fpath.absolute.path);
if (fpath.existsSync()) {
print("Project not found!!!");
} else {
@@ -38,6 +39,28 @@ class Project {
return Project(name, lang, fpath, editors, isGit, enableTerminal);
}
Map<String, dynamic> toJson() {
return {
"name": name,
"language": language,
"path": path.path,
"editors": editors,
"isGit": isGit,
"enableTerminal": enableTerminal,
};
}
factory Project.fromJson(Map<String, dynamic> data) {
return Project(
data["name"] as String,
data["language"] as String,
File(data["path"] as String),
(data["editors"] as List<dynamic>).map((a) => a.toString()).toList(),
data["isGit"] as bool,
data["enableTerminal"] as bool,
);
}
// bool validatePath(){
// return File
// }

11
lib/models/rand.dart Normal file
View File

@@ -0,0 +1,11 @@
import 'dart:math';
const _chars = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890';
Random _rnd = Random();
String getRandomString(int length) => String.fromCharCodes(
Iterable.generate(
length,
(_) => _chars.codeUnitAt(_rnd.nextInt(_chars.length)),
),
);