loadFile method
Implementation
Future<void> loadFile(String path) async {
var json = "";
if (path.startsWith("assets:")) {
json = await rootBundle.loadString(path.replaceFirst(":", "/"));
}
else {
final file = File(path);
try {
json = await file.readAsString();
}
catch (e) {
showErrorDialog(context, e.toString());
}
}
try {
var root = JSON.deserialize<WidgetData>(jsonDecode(json));
this.path = path;
if (!paths.contains(path))
paths.add(path);
flushSettings(write: true);
setState(() {
models = [root];
environment.get<MessageBus>().publish("load", LoadEvent(widget: root, source: this));
environment.get<MessageBus>().publish("selection", SelectionEvent(selection: null, source: this));
showInfoToast("loaded $path");
updateCommandState();
});
}
catch(e) {
showErrorDialog(context, e.toString());
}
}