CodeBlanks Logo Icon CodeBlanks

Dart and Flutter

Learn that Flutter uses the Dart language and why this pair was chosen.

The Dart language

Flutter apps are written in Dart. Dart is also an object-oriented, statically typed language developed by Google. During development a JIT compiler enables hot reload in seconds; for release builds an AOT compiler compiles directly to machine code.

String isim = 'Ada';   // cannot be null
String? takmaAd;         // can be null

Sound null safety

Dart's sound null safety separates nullable values from non-nullable ones at the type level. Adding ? after a type allows null; without it the compiler rejects null assignments. Null reference errors are caught before they crash the app.

int yas = 25;     // cannot be null
int? puan;         // can be null
puan = null;       // valid

Practice Null safety variables

In main, declare int yas = 25. Declare String? takmaAd and assign null. Then print yas and takmaAd with print.

Starter code

main.dart
void main() {
  // yas adında null olamayan int tanımla ve 25 ata

  // takmaAd adında null olabilen String tanımla, null ata

  // yas ve takmaAd'ı print ile yazdır

}

Sample solution

main.dart
void main() {
  int yas = 25;
  String? takmaAd;
  takmaAd = null;
  print(yas);
  print(takmaAd);
}

Expected output

25
null

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Why did Flutter choose Dart?

  • It does not support classes or inheritance
  • It requires no compilation step
  • JIT for hot reload and AOT for fast release builds Correct answer
  • It was designed only for web pages

Explanation: Dart's JIT and AOT modes give Flutter fast development and efficient release builds.

2 Nullable type

Question
int____ sayac;
Answer
int? sayac;

Explanation: Adding ? after a type allows null values.

3 Dart and Flutter

Term Meaning
JIT Enables hot reload in development
AOT Compiles release builds to machine code
Sound null safety Prevents null reference errors
Dart Flutter's programming language

All lessons in Beginner