Dart Data Types - Notes
Definition:
A data type is the characteristic of a variable that determines what kind of data it can hold. Data types include
primitive types like int, double, bool, etc., as well as collections like List, Map, Set.
1. int - Integer
Used to store whole numbers (positive or negative) without decimal points.
Ex:
int age = 25;
2. double - Decimal Number
Stores floating-point (decimal) numbers.
Ex:
double pi = 3.1416;
3. num - Super Type for int and double
Can hold both integers and decimal numbers.
Ex:
num a = 10;
a = 10.5;
4. String - Text or Characters
Stores a sequence of characters (text).
Ex:
String name = "TheXcode";
5. bool - Boolean
Stores true or false values.
Ex:
Dart Data Types - Notes
bool isLoggedIn = true;
6. var - Type Inference
Automatically detects and assigns the data type based on value.
Ex:
var city = "Indore";
7. dynamic - Changeable Type
Can hold any type of value and can change at runtime.
Ex:
dynamic value = 10;
value = "Hello";
8. List - Collection (like Array)
Stores an ordered group of values.
Ex:
List<String> names = ["Ram", "Shyam", "Golu"];
9. Map - Key-Value Pairs
Stores values as a pair of key and value.
Ex:
Map<String, int> marks = {"Math": 90, "English": 80};
10. Set - Unique Collection
Stores unique items (no duplicates).
Ex:
Set<int> ids = {1, 2, 3};