28

Is there a REPL for Dart to experiment with?

I tried inputing dart code in devtools in Dartium and that also didn't work.

So I couldn't find an easy way to play with various APIs in dart.

Günter Zöchbauer
  • 490,478
  • 163
  • 1,733
  • 1,404
ducky
  • 1,072
  • 1
  • 10
  • 21

4 Answers4

13

I tried inputing dart code in devtools in Dartium and that also didn't work.

I'm very new to Dart, but something I came across was that you CAN evaluate code in Dartium. In order to do so, you must first load a page with Dart code in it and then toggle this selector in the console from "javascript page context" to one that references a Dart package or Dart code.

enter image description here

Once you do that you should be able to execute Dart in the console:

enter image description here

As a VIM user, I hardly have to open the Dart Editor now :). I should also mention that breakpoints, hovering over stepped into code to get variable details, navigating the call stack, and some level of intellisense in the console also work. I couldn't get conditional breakpoints to work, though.

jriggins
  • 646
  • 8
  • 14
6

Though it is not really a REPL, you may find the Try Dart online tool useful for playing around. It's a bit slow, since it is actually compiling the Dart code to JavaScript in order to have it work within the browser.

There is also a console that someone built, which is probably better if you're looking for a real REPL, but it requires a bit of setup.

Pixel Elephant
  • 17,447
  • 5
  • 62
  • 79
  • I tried to build dart-console but I don't think its compatible with the new dart-sdk [0.6.15.3_r25822]. – ducky Aug 08 '13 at 11:50
  • I noticed that there is an [issue](https://code.google.com/p/dart/issues/detail?id=4409&thanks=4409&ts=1344375769) on google code for it. – ducky Aug 08 '13 at 18:06
4

There is an announcement about REPL for Dartium - see Nathanial's comment below. There are plans for Smalltalk like super-REPL. Here is what Gilad Bracha (member of the Dart team at Google) wrote on this subject in Is there a REPL or console for Dart:

"I don't see this as a language question at all. It is a matter of tooling and reflective library support. With proper mirror builder APIs, building a REPL would be trivial. As it sands right now, it can be quite challenging. And of course, REPL is not the ultimate goal - there are more advanced interactive tools, like workspaces in Smalltalk/Self/Newspeak, where you not only evaluate things interactively at some top level, but can inspect the resulting objects, evaluate within the scope of an individual declaration or object etc. I am sure we will get there in time - and i much prefer sooner than later."

Paul Jurczak
  • 5,766
  • 36
  • 58
  • According to news.dartlang.org, Dartium got a REPL on the 2nd of this month. That being said, I can't seem to find it. Just typing dart into the console doesn't seem to work for me, even at break points. http://news.dartlang.org/2013/10/faster-dart2js-and-new-html-editor-in.html – Nathanial Oct 24 '13 at 01:26
  • @Nathanial You are right, it mentions REPL. I better edit my answer. – Paul Jurczak Oct 24 '13 at 05:26
1

The correct answer is https://dartpad.dev/

That site didn't exist when the other answers were posted in 2013, but you've stumbled on this post after 2020. And now you know. https://dartpad.dev allows you to create and share new Dart snippets and even put them in a Flutter app running online. Very, very cool!

enter image description here

Rap
  • 6,250
  • 2
  • 45
  • 80