About Me

I have decades of experience is software development using .Net Technologies, PHP and wordpress. I love coding and discovering new tech.

Blog

Flutter Basics: Variables and Loops (Quick Reference)

Coding, Flutter

Flutter Basics: Variables and Loops (Quick Reference)

Posted on July 11, 2025  - By Kaustav Halder - 0 Comments

If you’re just starting with Flutter or need a quick refresher on Dart fundamentals, this post covers the essentials of variables and loops. It’s designed for fast reference, without unnecessary extras.

Dart and Flutter

Flutter apps are built using Dart, a modern, object-oriented language developed by Google. Understanding Dart basics is essential for writing effective Flutter code.

Variables in Dart

Variables store data. Dart supports both explicitly typed and type-inferred variable declarations.

Declaring Variables

int age = 25;               // Integer
double height = 5.9;        // Decimal
String name = "Kaustav";    // Text
bool isActive = true;       // Boolean

Using var, final, and const

var city = "Delhi";         // Type inferred as String
final country = "India";    // Value set once, at runtime
const pi = 3.14;            // Compile-time constant
  • Use var when the variable’s type can be inferred and might change.
  • Use final for values that are assigned once and do not change.
  • Use const for values that are constant at compile time.

Loops in Dart

Loops are used to execute a block of code multiple times.

For Loop

for (int i = 0; i < 5; i++) {
  print("Count: $i");
}

For-in Loop

Ideal for iterating over collections like lists.

List fruits = ["Apple", "Banana", "Mango"];
for (var fruit in fruits) {
  print(fruit);
}

While Loop

int i = 0;
while (i < 3) {
  print("i is $i");
  i++;
}

Do-While Loop

int j = 0;
do {
  print("j is $j");
  j++;
} while (j < 3);

String Interpolation

Use string interpolation to embed variables inside strings.

String name = "Flutter";
print("Hello, $name");  // Output: Hello, Flutter

Summary Table

ConceptExample
Variableint count = 0;
Inferred Typevar name = "Dart";
Finalfinal version = "1.0";
Constconst pi = 3.14;
For Loopfor (int i = 0; i < 3; i++)
For-in Loopfor (var item in list)
While Loopwhile (condition)
Do-While Loopdo { } while (condition)

Practice

To practice Dart code without setting up a project, visit https://dartpad.dev.

If you’d like a follow-up guide on conditionals, functions, or classes, let me know.



About Kaustav

I have decades of experience is software development using .Net Technologies, PHP and wordpress. I love coding and discovering new tech.


0 Comments

Be the first to comment


Leave a reply

Leave a Reply

Your email address will not be published. Required fields are marked *