#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 FlutterDay 3
Variables, data types, operators and expressions are the building blocks of any programming language. In this day, you will learn how to declare and initialize variables of different data types, and how to use operators and write conditional expressions.
Project - BMI Calculator
Write a program to calculate and print BMI given the user’s weight and height.
BMI = weight / (height * height)
By the end of this day, you should have a good understanding of how to declare and initialize variables of different data types, and how to use string interpolation to print messages, how to use operators and write conditional expressions.
Review the basics of variables and data types in Dart. You can use the Dart documentation to learn more about these concepts (https://dart.dev/guides/language/language-tour#variables).
You can declare and initialize variables of different data types, such as int, double, String, and boolean. For example:
void main() {
int age = 30;
double height = 1.75;
String name = 'John';
bool isStudent = true;
}
void main() {
int age = 30;
double height = 1.75;
String name = 'John';
bool isStudent = true;
print('My name is $name.');
print('I am $age years old and $height meters tall.');
print('Am I a student? $isStudent');
}
Experiment with declaring and initializing variables of different data types, and using string interpolation to print messages using these variables.
Experiment with arithmetic operators (+, -, *, /, %)
and comparison operators (>, <, >=, <=, ==, !=)
. For example:
void main() {
int a = 10;
int b = 5;
print(a + b); // 15
print(a - b); // 5
print(a * b); // 50
print(a / b); // 2.0
print(a % b); // 0
print(a > b); // true
print(a < b); // false
print(a >= b); // true
print(a <= b); // false
print(a == b); // false
print(a != b); // true
}
void main() {
int age = 25;
if (age >= 18) {
print('You are an adult.');
} else {
print('You are not yet an adult.');
}
}
This will print the message You are an adult.
to the console, since the age variable is greater than or equal to 18.
(&&, ||, !)
.More projects
Enjoying? Tell your friends.
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 FlutterJoin 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!