void main() {
  print('Welcome to Online IDE!');
  print('Start coding in Dart...');
}

Press Run or Ctrl ↵ to execute main.dart.
Type program input here while it runs.

Dart

Online Dart Compiler

Your program runs with dart main.dart on Dart 3.14, starting in main(), with the libraries of the Dart SDK. stdin.readLineSync() waits for you to type in the terminal.

Try it above

How Dart runs here

Versions
Dart 3.14
Run
dart main.dart
Limits per run
512 MB memory, 15 s of CPU time on half a core, 2 MB of output
Time
Up to 10 minutes a run (30 on a paid plan); waits 2 minutes for input (5 on a paid plan)
Sandbox
Each run gets its own Linux sandbox with no network access. Text files your program writes next to your code open as new tabs.

A Dart program that reads input

This main.dart reads numbers, sorts them, and returns two values at once as a Dart 3 record:

Dart
import 'dart:io';
import 'dart:math';

(int, int) range(List<int> xs) => (xs.reduce(min), xs.reduce(max));

void main() {
  stdout.write('How many numbers? ');
  final n = int.parse(stdin.readLineSync()!.trim());
  final nums = <int>[];
  for (var i = 1; i <= n; i++) {
    stdout.write('Number $i: ');
    nums.add(int.parse(stdin.readLineSync()!.trim()));
  }
  nums.sort();
  final (lo, hi) = range(nums);
  final sum = nums.reduce((a, b) => a + b);
  print('Sorted: ${nums.join(' ')}');
  print('Range: $lo to $hi, average: ${(sum / n).toStringAsFixed(2)}');
}
Terminal
$ dart main.dart
How many numbers? 4
Number 1: 12
Number 2: 7
Number 3: 30
Number 4: 5
Sorted: 5 7 12 30
Range: 5 to 30, average: 13.50

Reading input in Dart

  • stdin.readLineSync() returns String?, because input can end. Null safety makes you handle that: add ! as above, or give a default with ?? ''.
  • int.parse() throws on anything that isn’t a whole number, including a line with two numbers in it. int.tryParse() returns null instead, so you can ask again.
  • A loop that reads until readLineSync() returns null never ends here, because the terminal doesn’t send an end of input. Read a count first, or stop on an empty line.

What isn’t available here

  • Flutter. There’s no Flutter SDK and no screen, so widgets and package:flutter imports don’t work.
  • pub packages such as http, args or collection. There’s no pubspec.yaml and runs are offline. dart:core, dart:io, dart:math, dart:convert, dart:collection and dart:async are there.
  • Browser libraries such as dart:html and dart:js_interop. The program runs on the Dart VM.

Other .dart files next to main.dart can be imported by name: import 'utils.dart';.

Errors you’ll see

  • A compile error saying a value of type String? can’t be assigned to a variable of type String: readLineSync() can return null. Add ! or ??.
  • Unhandled exception with a FormatException from int.parse(): the line wasn’t a number. Trim it, or use int.tryParse().
  • A null check operator used on a null value: a ! met null. Check the value before using !.

Questions

Which Dart version does this use?

Dart 3.14, run on the Dart VM with dart main.dart. Records, patterns, sealed classes and null safety all work.

Can I run Flutter apps here?

No. The playground runs Dart programs that print to the terminal. Flutter needs its SDK and a screen to draw on.

How do I read a number from input in Dart?

import 'dart:io'; then int.parse(stdin.readLineSync()!.trim()). Type the number in the terminal while the program runs.