Thuta Learning
BasicProgrammingbeginner

Data Types

Relax. We'll talk through this in plain words — no textbook voice.

Dart is a strongly typed language, so every value has a type. Understanding types helps you cut down on errors and makes your code's intent clearer.

dart
void main() {
  int students = 35;
  double rating = 4.8;
  String course = 'Dart Basic';
  bool isPublished = true;

  print(course.runtimeType);
  print('Students: $students');
  print('Rating: $rating');
  print('Published: $isPublished');
}

runtimeType is handy when you want to check a value's actual type. When you're debugging and want to know "what type is this value, exactly?", give it a try.

You should see
String Students: 35 Rating: 4.8 Published: true

Easy traps

  • You can't put a String into a number type, like int age = '20';. Since user input often comes in as a String, you'll need to parse it if you want to treat it as a number.
Data Types | Thuta Learning