Interactive shell

suggest change

An interactive shell or Read-Eval-Print Loop (REPL) enables developers to experiment with language syntax, test regular expressions, evaluate mathematical formulas, and prototype small functions immediately without setting up a full project or compiling build targets.

While Dart does not ship a built-in terminal REPL command like Python or Node.js by default, the Dart ecosystem provides several official and community solutions for interactive development.


Interactive Browser Shell: DartPad

The official online interactive shell for Dart and Flutter is DartPad (dartpad.dev):


Evaluating Code from the Command Line

1. Running a Single File with dart run

dart run doesn't read code from stdin (without a file argument it runs the current package and fails if there's no pubspec.yaml). But it runs any standalone .dart file without a project, so write the snippet to a file and run it:

# Evaluate an expression from the shell
echo "void main() => print('Result: \${10 * 4 + 2}');" > eval.dart
dart run eval.dart

Output:

Result: 42

2. Multi-line Snippets with a Heredoc

There is no dart run - mode for reading a program from stdin. For multi-line snippets, use a shell heredoc to create the file:

cat > eval.dart <<'EOF'
void main() {
  final items = [1, 2, 3, 4, 5];
  final evens = items.where((n) => n.isEven).toList();
  print('Evens: $evens');
}
EOF
dart run eval.dart

Output:

Evens: [2, 4]

CLI REPL Tools

Community packages bring interactive REPL shells directly to the terminal. The most complete one for Dart 3 is interactive. You can activate it globally using the Dart package manager:

# Globally activate a CLI REPL tool
dart pub global activate interactive

Once activated, launch the shell:

interactive

Interactive session (variables are declared without var/final):

>>> greeting = "Hello, Dart!"
Hello, Dart!
>>> greeting.toUpperCase()
HELLO, DART!
>>> 100 ~/ 7
14
>>> [1, 2, 3].map((x) => x * 10).toList()
[10, 20, 30]
>>> exit()

Interactive Debug Console in IDEs

When developing in Visual Studio Code or IntelliJ / Android Studio:

  1. Place a breakpoint anywhere inside your Dart code.
  2. Launch a debug session (F5).
  3. Open the Debug Console tab.
  4. Type any valid Dart expression into the input prompt to evaluate it live within the current execution scope:
// Inside Debug Console at breakpoint:
currentUser.email
// "alice@example.com"

items.where((i) => i.price > 50).length
// 3

DateTime.now().toIso8601String()
// "2026-10-17T15:30:00.000Z"

The Debug Console has access to all local variables, instance fields, and imported library methods in the current call frame.


Interactive Scripting with Shebang

On Unix-like systems (Linux and macOS), you can write interactive scripts that execute directly like shell scripts:

Create a file named calc:

#!/usr/bin/env dart

import 'dart:io';

void main(List<String> args) {
  if (args.isEmpty) {
    stdout.write('Enter expression (e.g. 10 * 20): ');
    final input = stdin.readLineSync();
    print('You entered: $input');
  } else {
    print('Arguments: $args');
  }
}

Make it executable and run it:

chmod +x calc
./calc

Best Practices

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents