loadSchematicFromFile method
Load schematic from file picker.
Uses file_selector which works correctly on Linux, macOS, Windows, and
web — unlike file_picker which has issues on Linux GTK.
Implementation
Future<void> loadSchematicFromFile() async {
try {
const typeGroup = XTypeGroup(
label: 'JSON netlists',
extensions: <String>['json'],
);
final xfile = await openFile(acceptedTypeGroups: <XTypeGroup>[typeGroup]);
if (xfile == null) {
return;
}
setLoading(loading: true);
if (kPerfLog) {
debugPrint('[PERF] loadSchematicFromFile: reading ${xfile.name}...');
}
final jsonData = await xfile.readAsString();
if (kPerfLog) {
debugPrint(
'[PERF] loadSchematicFromFile: read ${jsonData.length} chars, '
'calling computeLayout...',
);
}
setFileName(xfile.name);
await computeLayout(jsonData);
} on Exception catch (e) {
if (kPerfLog) {
debugPrint('[PERF] loadSchematicFromFile: EXCEPTION: $e');
}
setLoading(loading: false, errorMessage: 'Failed to load file: $e');
}
}