fixed nullable mess with editor ids
Some checks failed
Build CI / AMD64 Build (push) Has been cancelled
Build CI / ARM64 Build (push) Has been cancelled

This commit is contained in:
2026-02-28 15:20:26 +05:30
parent 07f222a87e
commit 4f0503ca50
8 changed files with 67 additions and 53 deletions

View File

@@ -19,31 +19,30 @@ class GlobalModel extends ChangeNotifier {
SharedPreferences.getInstance().then((a) {
print("Loaded sp");
prefs = a;
editors = [Editor("", "None", "NANII", "", "")];
id2EdtMap = {"NANII": 0};
if (prefs.containsKey(kEditorsKey)) {
String edtData = prefs.getString(kEditorsKey)!;
List<dynamic> data = jsonDecode(edtData);
editors = [];
id2EdtMap = {};
for (var (i, d) in data.indexed) {
var localEdt = Editor.fromJson(d);
editors.add(localEdt);
id2EdtMap[localEdt.id] = i;
id2EdtMap[localEdt.id] = i + 1;
}
} else {
editors = [];
prefs.setString(kEditorsKey, jsonEncode(editors));
}
print(id2EdtMap);
final List<String> idList = id2EdtMap.keys.toList();
projects = [];
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));
projects.add(Project.fromJson(d, idList));
}
} else {
projects = [];
prefs.setString(kProjectsKey, jsonEncode(projects));
}
print(projects);
@@ -61,7 +60,11 @@ class GlobalModel extends ChangeNotifier {
}
void saveEditorState() {
var arst = editors.map((a) => a.toJson()).toList();
var tempEditors = editors;
tempEditors.removeWhere((a) => a.id == "");
List<Map<String, dynamic>> arst = tempEditors
.map((a) => a.toJson())
.toList();
prefs.setString(kEditorsKey, jsonEncode(arst));
}
@@ -112,12 +115,16 @@ class GlobalModel extends ChangeNotifier {
void addEdt(Editor edt) {
editors.add(edt);
print(editors);
id2EdtMap[edt.id] = editors.length - 1;
saveEditorState();
notifyListeners();
}
void delEdt(int index) {
editors.removeAt(index);
Editor removed = editors.removeAt(index);
int remmedID = id2EdtMap.remove(removed.id)!;
assert(index == remmedID);
saveEditorState();
notifyListeners();
}
@@ -130,8 +137,8 @@ class GlobalModel extends ChangeNotifier {
return editors[index];
}
int? getFromID(String? id) {
return id2EdtMap[id];
int getEdtPosFromID(String id) {
return id2EdtMap[id] ?? 0;
}
// Editing controller