CodeBlanks Logo Icon CodeBlanks

Summary - First app

Combine create, runApp and hot reload to ship your first running app.

First app summary

To write your first working Flutter app: generate the project skeleton with flutter create, call runApp with MaterialApp in the main function inside lib/main.dart, and launch it on a device with flutter run. During development, press r to hot reload and iterate quickly.

flutter create ilk_uygulama
cd ilk_uygulama
flutter run
# edit code, press 'r' for hot reload

Practice Return step by step

Write a function adim that takes an int n parameter. If n == 1 return 'create', if n == 2 return 'runApp', otherwise 'reload'. In main, print adim(1), adim(2) and adim(3) with print.

Starter code

main.dart
void main() {
  // adim(1), adim(2), adim(3) çağrılarını print ile yazdır

}

// adim fonksiyonunu tanımla
// 1 dönerse 'create', 2 dönerse 'runApp', değilse 'reload'

Sample solution

main.dart
void main() {
  print(adim(1));
  print(adim(2));
  print(adim(3));
}

String adim(int n) {
  if (n == 1) return 'create';
  if (n == 2) return 'runApp';
  return 'reload';
}

Expected output

create
runApp
reload

Questions and answers

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

1 Which command launches the first Flutter app on a device?

  • flutter pub get
  • flutter doctor
  • flutter build
  • flutter run Correct answer

Explanation: flutter run launches the app on a connected device or emulator; build compiles, pub get downloads packages.

2 Complete the root widget

Question
void main() => runApp(MaterialApp(home: ____('İlk uygulama')));
Answer
void main() => runApp(MaterialApp(home: Text('İlk uygulama')));

Explanation: The home parameter takes a widget; to show text you use Text.

3 First app combined

Term Meaning
Proje iskeleti Created by flutter create
Kök widget Attached to screen via runApp
Material tema Comes from MaterialApp
Hızlı yineleme Provided by hot reload

All lessons in Beginner