Dart Basics: Variables, Types and Operators

Google Flutter 11 min min read Updated: Nov 16, 2026 Beginner
Dart Basics: Variables, Types and Operators
Beginner Topic 1 of 8

Why Learn Dart First?

Flutter apps are written in Dart. Dart looks familiar if you know Java, JavaScript, C# or Kotlin. In this module you learn only what you need for Flutter. You can try every example online in DartPad at dartpad.dev with no installation.

Your First Dart Program

dart void main() { print('Hello, Dart!'); }

Every Dart program starts with the main() function. Statements end with a semicolon.

Variables

dart void main() { String name = 'Asha'; int age = 25; double height = 1.62; bool isStudent = true; print('$name is $age years old'); }
TypeStoresExample
intWhole numbers42
doubleDecimal numbers3.14
StringText'hello' or "hello"
booltrue or falsetrue
ListOrdered collection[1, 2, 3]
MapKey and value pairs{'a': 1}
dynamicAny type (avoid when possible)anything

var, final and const

dart var city = 'Mumbai'; // type is inferred as String city = 'Delhi'; // allowed final today = DateTime.now(); // set once at runtime, cannot change after const pi = 3.14159; // compile-time constant, never changes
KeywordCan change later?Value known when?
varYesAny time
finalNo (set only once)At runtime
constNoBefore the program runs
Good habit: Prefer final for variables that do not change. It prevents mistakes. Use const for fixed values and fixed widgets.

String Interpolation

dart var item = 'Coffee'; var price = 3.5; print('$item costs \$${price * 2} for two'); // Coffee costs $7.0 for two print('Name length: ${item.length}'); // use {} for expressions

Useful String Methods

dart var s = ' Flutter is fun '; print(s.trim()); // Flutter is fun print(s.toUpperCase()); print(s.contains('fun')); // true print(s.replaceAll('fun', 'great')); print('a,b,c'.split(',')); // [a, b, c]

Numbers

dart int a = 10; double b = 3.0; print(a / 4); // 2.5 (division always gives a double) print(a ~/ 4); // 2 (integer division) print(a % 3); // 1 (remainder) print(a.toDouble()); print(3.7.round()); // 4 print(int.parse('42') + 1); // 43

Operators

KindOperators
Arithmetic+ - * / ~/ %
Comparison== != > < >= <=
Logical&& || !
Assignment= += -= *= /= ??=
Increment++ --
Null-aware?? ?. ??= !

Conclusion

You now know how to store data, join strings and do math in Dart. Use final by default and enjoy type inference.

Quick Summary: Dart has int, double, String and bool. Use var, final and const, and use $ for string interpolation.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators