mobile-blockly / flutter_blockly

A Flutter Blockly visual programming editor.
MIT License
8 stars 3 forks source link

doubts about creating customized blocks #13

Open cprnn opened 2 weeks ago

cprnn commented 2 weeks ago

Hi, how are you? I'm programming a game in Flutter/Flame that uses the flutter_blockly library and having trouble integrating my custom blocks.

So far, I've created a .js file for these blocks and referenced it in the index.html in /lib, but following this logic hasn't been working properly (it's been showing errors importing and recognizing blockly.min.js).

Is there a process that must be carried out to create and include customized blocks to use with the library? My application is web-based.

Thank you very much in advance!

SerSerch commented 1 week ago

Hi! What version of flutter_blockly are you using? In version 1.5.1 no need to import blockly.min.js. All this is done by the library.

If you need to add your own code, you can do it through the script parameter

BlocklyEditorWidget(
          workspaceConfiguration: workspaceConfiguration,
          initial: initialJson,
          onInject: onInject,
          onChange: onChange,
          onDispose: onDispose,
          onError: onError,
          script: '''
          alert('start blockly ' + !!Blockly);
          ''',
        )

script is of type String. your file can be added to assets and then loaded using loadString for example

cprnn commented 1 week ago

Hello!

Yes, it's the 1.5.1. version. I'll try the loadString approach!

Thanks for answering and helping me with this!

SerSerch commented 1 week ago

Always happy to help you. Let me know if you have any problems.

SerSerch commented 11 hours ago

Hi! Did you get to do it?

cprnn commented 10 hours ago

Hello! I'm sorry for the delayed answer. Yes! It's working great now.

Thanks again for your help!

By the way, is it better to use the Javascript code generator for the custom blocks or the Dart one? I'm currently studying both to see which one would be better to use for the character movement (that is made using Flame). What's your opinion?

Thank you very much for your help before, and in advance!