Menu
×
   ❮   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP C C++ C# AWS W3.CSS HOW TO BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL SQLITE MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING HTML & CSS BASH RUST DART PLAYWRIGHT TOOLS MATH SHEETS POWER BI

Dart Tutorial

Dart HOME Dart Intro Dart Get Started Dart Syntax Dart Output Dart Comments Dart Variables Dart final and const Dart Data Types Dart Numbers Dart Strings Dart String Interpolation Dart String Methods Dart Booleans Dart Type Conversion Dart Null Safety Dart late Dart Operators Dart Arithmetic Dart Assignment Dart Comparison Dart Logical Dart Type Test Dart Null Operators Dart Cascade Dart If...Else Dart Switch Dart While Loop Dart For Loop Dart Break/Continue

Dart Collections

Dart Lists Dart Access List Items Dart Change List Items Dart Loop Lists Dart List Methods Dart Sets Dart Maps Dart Access Map Items Dart Loop Maps Dart Collection if/for Dart Spread Operator

Dart Functions

Dart Functions Dart Parameters Dart Named Parameters Dart Return Values Dart Arrow Functions Dart Anonymous Functions Dart Closures Dart Scope Dart Recursion

Dart Classes

Dart OOP Dart Classes/Objects Dart Constructors Dart Named Constructors Dart Factory Constructors Dart Getters and Setters Dart Static Members Dart Inheritance Dart Abstract Classes Dart Interfaces Dart Mixins Dart Extension Methods Dart Enums Dart Generics

Dart 3 Features

Dart Records Dart Patterns Dart Switch Expressions Dart Sealed Classes Dart Class Modifiers

Dart Errors

Dart Exceptions Dart Custom Exceptions

Dart Async

Dart Async Intro Dart Futures Dart async/await Dart Streams Dart Isolates

Dart Libraries

Dart Imports Dart Packages Dart Math Dart Dates Dart JSON Dart RegExp Dart User Input Dart Files Dart Testing

Dart Examples

Dart Examples Dart Exercises


Dart Output


Share

Dart Output (Print Text)

To show output in Dart, you use the print() function.

You put the value you want to show inside the parentheses:

Example

void main() {
  print('Hello World');
}
Try it Yourself »

Result:

Hello World

You can call print() as many times as you want.

Each call prints its value on a new line:

Example

void main() {
  print('I am learning Dart.');
  print('It is fun!');
  print('Dart is used to build apps.');
}
Try it Yourself »

Result:

I am learning Dart.
It is fun!
Dart is used to build apps.

Print Numbers

You can also print numbers.

Numbers are written without quotes:

Example

void main() {
  print(3);
  print(358);
  print(50000);
}
Try it Yourself »

Result:

3
358
50000

You can do math inside print(), and Dart prints the result:

Example

void main() {
  print(3 + 3);
  print(2 * 5);
}
Try it Yourself »

Result:

6
10


Print Several Values

print() takes exactly one value.

If you give it two values separated by a comma, the program does not run:

Example

void main() {
  print('Hello', 'World');
}
Try it Yourself »

Result:

main.dart:2:8: Error: Too many positional arguments: 1 allowed, but 2 found.
Try removing the extra positional arguments.
  print('Hello', 'World');
       ^
org-dartlang-sdk:///sdk/lib/core/print.dart:19:6: Context: Found this candidate, but the arguments don't match.
void print(Object? object) {
     ^^^^^

To print several pieces of text on one line, join them into one string with the + operator:

Example

void main() {
  print('Hello' + ' ' + 'World');
}
Try it Yourself »

Result:

Hello World

To put a value inside a string, write a dollar sign $ and then the variable name, or write ${} around a calculation:

Example

void main() {
  var name = 'Liam';
  print('My name is $name');
  print('5 + 3 is ${5 + 3}');
}
Try it Yourself »

Result:

My name is Liam
5 + 3 is 8

This is called string interpolation, and you will learn more about it in the String Interpolation chapter.


Print Without a New Line

print() always adds a new line after the value.

To print without a new line, use stdout.write().

stdout belongs to the dart:io library, so you must import it at the top of the file:

Example

import 'dart:io';

void main() {
  stdout.write('Hello ');
  stdout.write('World!');
  stdout.write(' I am on the same line.');
}
Try it Yourself »

Result:

Hello World! I am on the same line.

To start a new line inside a string, use the special character \n:

Example

import 'dart:io';

void main() {
  stdout.write('Apples\n');
  stdout.write('Bananas\n');
  print('Cherries\nOranges');
}
Try it Yourself »

Result:

Apples
Bananas
Cherries
Oranges

Note: In most programs, print() is all you need.

Use stdout.write() only when you want to build one line from several parts.



Free account

Track your progress

XP earned 0 Day streak 0 Spaces 0 League —

New

Learn in Adventure Mode W3Schools Adventure App

Coding fundamentals as bite-sized lessons and challenges.

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2026 by W3Schools. All Rights Reserved. W3Schools is Powered by W3.CSS.