I can save block on workspace with xml, json, how to load this on workspace
String _generatedCode = '';
String _CodeXml = '';
final BlocklyOptions workspaceConfiguration =
BlocklyOptions.fromJson(const {
'grid': {
'spacing': 12,
'length': 30,
'colour': '#b6b6b6',
'snap': true,
},
'toolbox': initialToolboxJson,
'theme': null,
// null safety example
'collapse': null,
'comments': true,
'css': null,
'disable': null,
'horizontalLayout': null,
'maxBlocks': 200,
'maxInstances': null,
'media': null,
'modalInputs': null,
'move': null,
'oneBasedIndex': null,
'readOnly': null,
'renderer': 'zelos',
'rendererOverrides': null,
'rtl': null,
'scrollbars': {
'horizontal': false,
'vertical': false
},
'sounds': true,
'toolboxPosition': null,
'trashcan': true,
'maxTrashcanContents': null,
'plugins': null,
'zoom': {
'controls': false,
'wheel': false,
'startScale': 0.6,
'maxScale': 1.0,
'minScale': 0.1,
'scaleSpeed': 0.5
},
'parentWorkspace': null,
});
void onInject(BlocklyData data) {
print('Injected: ${data.xml}');
}
onChange(BlocklyData data) {
setState(() {
// Check if there are any blocks in the workspace
if (data.js != null && data.js!.isNotEmpty) {
_generatedCode = data.js!; // Update with the generated code
} else {
_generatedCode = ''; // No blocks, so clear the generated code
}
//_generatedCode = jsonEncode(data);
_CodeXml = jsonEncode(data);
});
print('Changed: ${data.xml}');
}