Skip to main content

#30DaysMasterFlutter

Day 2: First Dart App

Day 2 of 30

First Dart app

Create and run your first Dart console application. This will allow you to get familiar with the Dart syntax and how to write a simple console application using it.

Project - Greet User

Create a Dart console application that asks the user for their name and prints a greeting message to the console.

Hello <name>!

By the end of this day, you should have a basic understanding of the Dart syntax and how to write a simple console application using it.

Tips

  • To create a new Dart console application, you can use the dart create command. The default template is a console application.
dart create greet_user
cd greet_user
dart run
  • To get user input in Dart, you can use the stdin.readLineSync() function. For example:
import 'dart:io';

void main() {
  print("Enter anything:");
  String? input = stdin.readLineSync();
  print("You entered: $input");
}
  • readLineSync() returns a nullable String?, because there may be no input. Handle the null case, for example with input ?? 'stranger'.

Resources

#30DaysMasterFlutter

Learn the basics of Flutter and Dart in 30 days! We provide a roadmap, resources, and project ideas to help you along your journey.

back to 30 Days to Master Flutter

Join our community on Discord to connect with fellow learners, share your progress, and get help with any questions you may have throughout the #30DaysMasterFlutter challenge. Join now and get started on your journey to mastering Dart and Flutter!

join now