Don't miss ourDecember livestream, with updates on Flutter and live Q&A!
Intro to Dart
Learn about the Dart programming language
To get started with Flutter, you need to have some familiarity with the Dart programming language, which Flutter applications are written in. This page is a gentle introduction to Dart, and if you're comfortable reading the code examples, feel free to skip this page. You do not need to be an expert in Dart to continue with this series.
Dart
#Flutter applications are built inDart, a language that will look familiar to anyone who's written Java, Javascript, or any other C-like language.
Installing Flutter also installs Dart, so you don't need to install Dart separately.
The following example is a small program that fetches data from dart.dev, decodes the returned json, and prints it to the console. If you're confident in your ability to understand this program, feel free to skip to the next page.
import'dart:convert';import'package:http/http.dart'ashttp;classPackage{finalStringname;finalStringlatestVersion;finalString?description;Package(this.name,this.latestVersion,{this.description});@overrideStringtoString(){return'Package{name:$name, latestVersion:$latestVersion, description:$description}';}}voidmain()async{finalhttpPackageUrl=Uri.https('dart.dev','/f/packages/http.json');finalhttpPackageResponse=awaithttp.get(httpPackageUrl);if(httpPackageResponse.statusCode!=200){print('Failed to retrieve the http package!');return;}finaljson=jsonDecode(httpPackageResponse.body);finalpackage=Package(json['name'],json['latestVersion'],description:json['description'],);print(package);} This program has two parts: thePackage class declaration, and the business logic, which is contained in themain function.
ThePackage class contains many of the most common features you'll use when working withclasses in Dart. This class has three members, and defines a constructor and a method.
The Dart language istype safe; it uses static type checking to ensure that a variable's value always matches the variable's static type. When defining a class, annotating the members withString is required, but it is often optional due to type inference. In themain function in this example there are many lines that start withfinal variableName =. These lines are type safe, despite not being explicitly given a type.
Dart also has built-insound null safety. In the example, thedescription member is declared with the typeString?. The? at the end ofString? means that this property can be null. The other two members cannot be null, and the program will not compile if you tried to set them tonull. You can see this demonstrated in the constructor for thePackage class. It takes two required, positional arguments and one optional, named argument.
Next in the example is themain function. All Dart programs, including Flutter apps, start with amain function. The function showcases several basic Dart language features, including using libraries, marking functions as async, making function calls, usingif statement control-flow, and more.
The main entrypoint in a starter Flutter app is inlib/main.dart. The defaultmain method looks like the following:
voidmain(){runApp(constMyApp());} Perform anyquick initialization (less than a frame or two)before callingrunApp(), though be aware that the widget tree hasn't been created yet. If you want to perform initialization that takes awhile, such as loading data from disk or over a network, do it in a way that won't block the main UI thread. For more information, check outAsynchronous programming, theFutureBuilder API,Deferred components, or theWorking with long lists cookbook recipe, as appropriate.
Every stateful widget has aninitState() method that is called when the widget is created and added to the widget tree. You can override this method and perform initialization there, though the first line of this methodmust besuper.initState().
Finally, hot reloading your app doesnot callinitState ormain again. Hot restart calls both.
If these features aren't familiar to you, you can find resources to learn Dart on theBootstrap into Dart page.
Next: Widgets
#This page is an introduction to Dart, and helps you become familiar with reading Flutter and Dart code. It's okay if you don't feel clear on all the code on this page, as long as you feel comfortable with thesyntax of the Dart language. In the next section, you'll learn about the building block of Flutter apps: widgets.
Feedback
#As this section of the website is evolving, wewelcome your feedback!
Unless stated otherwise, the documentation on this site reflects Flutter 3.38.1. Page last updated on 2025-10-30.View source orreport an issue.