Dart online compiler
Write Dart 3.13 console code below and run it free, with no sign-in and no ads. It runs on the Dart VM with dart:io, so stdin.readLineSync() reads each line you put in the Input tab. The same compiler is an API and an embeddable editor, for running Dart in your own app, course or docs.
Também em portuguêsTambién en español
Run Dart from your own app, bot or course. One API call returns the output, errors, exit code and run time. Free up to 100,000 runs a month, commercial use included, no card.
Checking a solution against several inputs? The Dart online compiler with test cases runs them all at once and marks each one passed or failed.
Dart 3 examples: records, patterns and async
A shopping list read from the Input tab, one item per line. A list pattern splits each line into its three parts, and a record returns two values from one function, both Dart 3 features.
import 'dart:io';
class Item {
final String name;
final double price;
final int qty;
Item(this.name, this.price, this.qty);
double get total => price * qty;
}
// A record returns two values without a new class (Dart 3).
(double, Item) summary(List<Item> items) {
final total = items.fold(0.0, (sum, item) => sum + item.total);
final biggest = items.reduce((a, b) => a.total >= b.total ? a : b);
return (total, biggest);
}
void main() {
final items = <Item>[];
for (var line = stdin.readLineSync(); line != null && line.isNotEmpty; line = stdin.readLineSync()) {
final [name, price, qty] = line.split(',');
items.add(Item(name.trim(), double.parse(price), int.parse(qty)));
}
final (total, biggest) = summary(items);
print('Items: ${items.length}');
print('Total: ${total.toStringAsFixed(2)}');
print('Biggest line: ${biggest.name} (${biggest.total.toStringAsFixed(2)})');
}With this input:
Notebook, 2.50, 4
Pen, 1.20, 10
Backpack, 24.99, 1it prints:
Items: 3
Total: 46.99
Biggest line: Backpack (24.99)main can be async. Here three Futures run at once, and Future.wait collects their results:
Future<String> greet(String name) async {
await Future.delayed(const Duration(milliseconds: 200));
return 'Hello, $name!';
}
Future<void> main() async {
print('Waiting...');
final greetings = await Future.wait(['Ada', 'Linus', 'Grace'].map(greet));
greetings.forEach(print);
}It prints Waiting..., then Hello, Ada!, Hello, Linus! and Hello, Grace!.
What runs your code
| Version | Dart 3.13 |
|---|---|
| Compiled with | No separate step: the run command compiles or interprets it |
| Run with | dart run code.dart |
| Limits | 30 seconds, 512 MB of memory (up to 2 GB through the API on Pro and above), 2 CPUs, 64 KB of output per stream, no network |
| Typical run | 1.42 s, and 1.86 s for the slowest 1 in 20 (how we measured) |
Good to know
- Runs with
dart runon the Dart 3.13 VM, which compiles the file as it starts. stdin.readLineSync()fromdart:ioreads the next line of the Input tab and returnsnullat the end.- Sound null safety is on, as in all Dart 3 code. An uncaught exception exits with code 255.
Dart compiler API
To run Dart from your own app, send the code and its input to the sync endpoint with an API key, and the output comes back in the response. It's free up to 100,000 runs a month, with no credit card: get a free API key. The API docs cover the async endpoint with callbacks and every response field.
curl -X POST https://api.onlinecompiler.io/api/run-code-sync/ \
-H "Authorization: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"compiler": "dart-3.13",
"code": "import '\''dart:io'\'';\n\nvoid main() {\n final name = stdin.readLineSync() ?? '\'''\'';\n print('\''Hello, $name!'\'');\n}",
"input": "Ada"
}'The response has output ("Hello, Ada!\n" here), error, exit_code, time and memory.
Embed a Dart compiler in your website
The editor above is the embeddable widget. Add the script and a div with your widget key, and your readers can edit and run the code without an account:
<script src="https://onlinecompiler.io/widget.js"></script>
<div class="runcode" data-key="YOUR_WIDGET_KEY" data-lang="dart-3.13">
<script type="text/plain">
import 'dart:io';
void main() {
final name = stdin.readLineSync() ?? '';
print('Hello, $name!');
}
</script>
<a data-credit href="https://onlinecompiler.io/">Runs on OnlineCompiler.io</a>
</div>On a platform that takes an iframe but not a script, such as many course sites, use the iframe embed. For Docusaurus, MkDocs, Sphinx and Mintlify, see runnable code examples in docs.
Other languages
Python, C, C++, Java, C#, F#, Go, Rust, PHP, Ruby, Haskell, TypeScript, JavaScript, SQL, DuckDB, Bash, Fortran, Visual Basic, Kotlin, R, Swift, COBOL, Perl, Julia, Pascal, Octave, Assembly, Lua, OCaml, Common Lisp, Erlang, Elixir, Prolog, D, FreeBASIC, Clojure, Groovy, Scala, Zig, Nim, Crystal, Ada, PowerShell, Racket, Objective-C.
Frequently asked questions
Is this Dart online compiler free?
Yes. Running Dart on this page needs no account and shows no ads. To run Dart from your own app or site, the API and the widget are free up to 100,000 runs a month, commercial use included.
Is there a Dart compiler API?
Yes. POST the code, the compiler id dart-3.13 and any input to https://api.onlinecompiler.io/api/run-code-sync/ with an API key, and the response holds the output, errors, exit code, run time and memory. It's free up to 100,000 runs a month, and the same key works for the other 45 languages.
Can my Dart program read input?
Yes. Type it in the Input tab before you run, and the program reads it with stdin.readLineSync() from dart:io, one line per call, which returns null once every line has been read. The whole input is sent when you press Run, so a program can't ask for more while it runs.
Can I use Dart libraries?
The Dart core libraries, such as dart:io, dart:math, dart:convert and dart:async. Packages from pub.dev can't be added, and programs have no network access.
Can I run Flutter code here?
No. This runs console Dart on the Dart VM, with no Flutter SDK and no screen, so importing package:flutter fails with "Couldn't resolve the package 'flutter'". Flutter apps need the Flutter SDK.
Why do I get "A value of type 'String?' can't be assigned"?
Because stdin.readLineSync() returns String?: it gives null when the input runs out, and Dart 3's null safety won't put that in a String. Write stdin.readLineSync() ?? '' to get an empty string instead of null, or stdin.readLineSync()! when the Input tab always has that line.
Do async and await work?
Yes. main can be async, and await, Future.delayed and Future.wait work, as in the second example above.
Can I share or save my code?
Yes. Share gives you a link that anyone can open and run, lasts 90 days and needs no account. Save keeps the code in your OnlineCompiler.io account until you delete it. When you are signed in, each run you make on this page is also kept in your account's run history.
How long can a program run?
Up to 30 seconds, with 512 MB of memory (up to 2 GB through the API on Pro and above) and 2 CPUs. A program still running at 30 seconds is stopped with exit code 124, and output over 64 KB per stream is cut.
Where does my code run?
On our servers, in a fresh gVisor sandbox with no network access that is deleted when the run ends. Each run is kept in execution history with its output; the security page says what is stored.