fzyzcjy / dart_interactive

REPL (interactive shell) for Dart, supporting 3rd party packages, hot reload, and full grammar
https://github.com/fzyzcjy/dart_interactive
MIT License
223 stars 13 forks source link

feature: enable Flutter support #99

Open csells opened 1 month ago

csells commented 1 month ago

I'd really love to be able to build dartpad as an interactive session with your package. Would such a thing be possible?

welcome[bot] commented 1 month ago

Hi! Thanks for opening your first issue here! :smile:

csells commented 1 month ago

@fzyzcjy what do you think?

fzyzcjy commented 1 month ago

If you can have the Dart VM service available then I think yes. Not examined whether this is possible though.

csells commented 1 month ago

The dart vm service is available when you're running a Flutter app. You can see that when you do flutter run.

fzyzcjy commented 1 month ago

IIRC when in release mode it is not there. But you may somehow embed or enable it I guess.

csells commented 1 month ago

Debug mode is fine; this would be for development anyway.

fzyzcjy commented 1 month ago

Oh if so then I guess it is pretty possible.

csells commented 1 month ago

Cool. Any idea how to get it going?

fzyzcjy commented 1 month ago

May I know a bit more details? For example, suppose your question is "a dartpad-like app that can have interactivity", then the simplest way may be: Have a text field and a text displayer in Flutter app, and when user enters text, just call dart_interactive's API (it does not have a very good one since I did not consider such usage, but it is not hard to make one).

Btw, for that usage, jupyter hub (or jupyter lab) may also be of interest. Similar to how Python/Julia/... can have nice interactivity there, we can use dart_interactive to make Dart do something similar. (Jupyter is a very popular notebook that is widely used in e.g. deep learning)

csells commented 1 month ago

May I know a bit more details? For example, suppose your question is "a dartpad-like app that can have interactivity", then the simplest way may be: Have a text field and a text displayer in Flutter app, and when user enters text, just call dart_interactive's API (it does not have a very good one since I did not consider such usage, but it is not hard to make one).

Yep. That's what I'm thinking about. Just like dartpad.dev, but without the server-side round-trip to do the compilation or the restriction on package imports.

Btw, for that usage, jupyter hub (or jupyter lab) may also be of interest. Similar to how Python/Julia/... can have nice interactivity there, we can use dart_interactive to make Dart do something similar. (Jupyter is a very popular notebook that is widely used in e.g. deep learning)

That would be another great usage. I'd love to have a Dart Notebook that used Flutter widgets for visualizations.

I'm happy to work on either of these with you if you can show me how to get the basics working.

fzyzcjy commented 1 month ago

Hmm I am a bit confused, do you want to have the hot reloaded code be Flutter code or pure Dart code? If pure dart code, then my suggestions above holds. If Flutter code, then one possible way is to develop code in e.g. VSCode and tap save, and it will be auto hot-reloaded.

csells commented 1 month ago

ha. thanks. yes. I'm familiar with how VSCode works. I'm suggesting Flutter code as hosted in dartpad.dev, but without the server-side compile round-trip or the package restrictions.

fzyzcjy commented 1 month ago

Hmm, so do you mean to have a webpage and let users do not need to have Flutter installed locally? Then I guess it may not be easy, since Dart web does not use Dart VM but instead use javascript. But maybe the new dart wasm helps?

csells commented 1 month ago

it wouldn't have to be on the web to start -- a local developer machine that can have a dartpad-like experience w/ Flutter installed would be useful, too. No need for VSCode and a project and the infrastructure -- just a text field on the left and the rendered Flutter on the right, updated in real-time as you type.

The Windows community has had something called XamlPad for a long time that does exactly this and it's super useful.

XamlPad

fzyzcjy commented 1 month ago

Ah I see! Then another way is to setup a local folder and do flutter run in the background, and when users enter text in the TextField, sync the code to that folder, and input r in the flutter run process to tell it hot reload.

csells commented 1 month ago

worth a try for sure