Dart Compiler

Code
Output

        

What Is the Dart Online Compiler?

This tool lets you compile and run Dart programs directly in your browser without installing the Dart SDK on your machine. Whether you are learning Dart for the first time or quickly testing null safety features and async patterns, this compiler provides a fast way to write and execute Dart code online.

Your code must include a void main() entry point, which is the standard starting function for Dart programs. You can accept command-line arguments with List<String> args and use print() to display output. Core libraries like dart:math, dart:async, and dart:io are available for import.

All code executes on a remote sandboxed server powered by the Piston API. Your browser sends the source code to the server, which compiles and runs the Dart program inside an isolated container. Dart's strong type system and null safety checks are fully enforced during compilation.

How It Works

  1. Write your Dart code in the editor panel. The editor starts with a simple "Hello, Dart!" example using void main(), but you can replace it with any valid Dart program.
  2. Provide input in the STDIN field if your program reads from standard input using stdin.readLineSync() from dart:io. Leave this field empty if your program does not require input.
  3. Add command-line arguments in the Args field if your program reads from the args parameter of main(). Enter arguments separated by spaces.
  4. Click the Run button to send your code to the Piston execution server. The server compiles your Dart source code with the Dart SDK, then runs it and captures all output.
  5. View the results in the Output panel. You will see everything your program prints to standard output, along with any compiler errors including type mismatches, null safety violations, or runtime exceptions.

Step-by-Step Example

Suppose you want to write a program that reads a name from standard input and prints a personalized greeting using null safety. Here is how you would do it:

First, type the following code into the editor panel:

import 'dart:io';

void main() {
    stdout.write("Enter your name: ");
    String? name = stdin.readLineSync();

    if (name != null && name.isNotEmpty) {
        print("Hello, $name! Welcome to Dart.");
    } else {
        print("Hello, stranger!");
    }
}

This example demonstrates several Dart features: import for loading the dart:io library, nullable types with String?, stdin.readLineSync() for reading input, null checking, and string interpolation with $name.

Next, go to the STDIN field and type a name, for example Alice. This value will be read by readLineSync() when the program runs.

Now click the Run button. The compiler builds and executes your Dart source code with the provided input. After a moment, the Output panel displays the result:

Enter your name: Hello, Alice! Welcome to Dart.

If you leave the STDIN field empty and click Run again, the output changes to the fallback greeting. This workflow makes it easy to test different inputs and observe how null safety behaves.

Use Cases

Limitations and Notes

Frequently Asked Questions

What Dart version does this compiler use?

It uses the latest Dart version available through the Piston execution engine.

Does this compiler support null safety?

Yes, sound null safety is enabled. You can use nullable types, the ? operator, late variables, and required parameters.

Can I build Flutter apps here?

No, this compiler runs console Dart only. Flutter framework and widget rendering are not available in this environment.

Does async/await work?

Yes, you can use async, await, Future, Stream, and other asynchronous programming features in your Dart code.

Can I use classes and mixins?

Yes, Dart classes, abstract classes, mixins, interfaces, and inheritance all work as expected in this compiler.

Can I import pub packages?

No, the pub package manager is not available. Only Dart core libraries and the standard SDK libraries can be imported.

Does Dart use strong typing here?

Yes, Dart is a strongly typed language. The compiler enforces type checking, type inference with var and final, and generics.

Can I read user input with stdin?

Yes, use stdin.readLineSync() from dart:io to read input. Provide your input data in the STDIN field before running.

Sources and References

Related Compilers