r/FlutterDev • • Jul 10 '20

Community StackOverflow: Add support for Flutter code snippets

https://meta.stackoverflow.com/questions/399252/add-support-for-flutter-dart-code-snippets
138 Upvotes

9 comments sorted by

8

u/[deleted] Jul 10 '20 edited Jul 10 '20

One of the DartPad maintainers responded:

I'm one of the maintainers for DartPad. I was really stoked to see this question, and I thought I'd respond with a little more info from our end.

First, we'd love to see an integration like this. DartPad is intended to be a flexible learning tool that people can drop into their existing stuff. If the StackExchange folks want to use DartPad that way, it should work out of the box, and we'd be happy to help with any feature requests.

I believe questions like this have come up before for other editors (jsFiddle, for instance), and there's a concern about keeping the code on StackOverflow itself, so this site can be the source of truth. DartPad can theoretically load a snippet from any server that can serve it with proper CORS headers, so it's possible an approach that kept the source code in the post and added a link to open it in DartPad might be a more ideal solution.

Also, it's possible to use DartPad's analysis and compilation backend on its own and build a completely new front-end just for SO. That's the strategy CodePen.io took when adding their new Flutter editor, and so far it's working out well.

While I'm a regular SO user, I don't venture into meta very often, so if this should have been a comment rather than an answer, forgive me. I wanted to say something, though, since y'all were talking about one of my favorite projects. :)

- RedBrogdon, https://meta.stackoverflow.com/a/399263/1674992

13

u/Alexander_Bourne Jul 10 '20

UPVOTE that question, that would be great.

3

u/[deleted] Jul 10 '20

It would be great but there are many many other way more popular frameworks and languages that they haven't added support for - Python, React, Typescript, etc. So I wouldn't hold your breath.

2

u/[deleted] Jul 10 '20 edited Jul 10 '20

React/JSX and TypeScript are both supported with the Babel option.

Python/C etc. can't run in the end user's browser (would require compute resources), which is why they haven't been implemented. Adding DartPad support just requires swapping out an iframe.

A StackExchange engineer on this exact topic:

There are a large number of languages for which runnable snippets would be nice to illustrate problems/solutions quickly, but would have to be run on the backend.

– CertainPerformance Aug 25 '19 at 20:43

2

u/[deleted] Jul 10 '20

Those can't run in the browser, which is why they haven't been implemented.

The absolutely can. There are loads of Python implementations that run in the browser: Skulpt, Brython, PyPyJs, PyIodide and probably more.

Didn't know about React/Typescript though - thanks!

1

u/[deleted] Jul 10 '20

Like I said, you can already use Typescript with the Babel option. You could always go make your own thread on the Python issue? Agreed that they could support it if they really wanted to.

1

u/dragneelfps Jul 10 '20

not sure how is this even gonna help much. most code i have seen are incomplete as answers, only focusing on the main part.

1

u/[deleted] Jul 10 '20

most code i have seen are incomplete

This is how it would help. Enabling users to copy-paste their code would mean more complete, reproducible examples included in more questions.

It's genuinely just repetitive to constantly ask users to get their example working on DartPad when it could be natively available as an option.

2

u/walross_pvp Jul 10 '20

that would be great