Popular Searches
Popular Course Categories
Popular Courses

Strings, numbers, Boolean values, lists, and other data types

Strings, numbers, Boolean values, lists, and other data types

Introduction to Dart


 

Strings, Numbers, Boolean Values, Lists, and Other Data Types in Dart

 


    Dart provides several built-in data types for storing and working with different kinds of
    information. Understanding strings, numbers, Boolean values, lists, sets, maps, and other
    data types is essential for developing Flutter applications. JustAcademy's Flutter curriculum
    includes Dart Programming Fundamentals covering variables, data types, operators, and
    collections such as List, Set, and Map. :contentReference[oaicite:0]{index=0}
 

 


    Explore the complete Flutter course:
           target="_blank"
       rel="noopener noreferrer">
      JustAcademy Flutter Training
   

 

 


    Register for a course demo:
           target="_blank"
       rel="noopener noreferrer">
      Register for Course Demo
   

 

 


 

1. What Are Data Types in Dart?

 


    A data type defines the kind of value that can be stored and used in a Dart program.
    Different data types are useful for different types of information.
 

 

For example:

 

String name = "Rahul";
int age = 25;
double price = 499.99;
bool isLoggedIn = true;

 


    Here:
 

 


       
  • String stores text.

  •    
  • int stores whole numbers.

  •    
  • double stores decimal numbers.

  •    
  • bool stores true or false.

  •  

 

2. Main Dart Data Types

 


   
     
       
       
       
     
   
   
     
       
       
       
     
     
       
       
       
     
     
       
       
       
     
     
       
       
       
     
     
       
       
       
     
     
       
       
       
     
     
       
       
       
     
     
       
       
       
     
     
       
       
       
     
     
       
       
       
     
     
       
       
       
     
   
 
Data TypePurposeExample
StringStores text"Hello Dart"
intStores whole numbers25
doubleStores decimal numbers99.99
numStores integer or decimal numbers100, 10.5
boolStores true or falsetrue
ListStores an ordered collection[1, 2, 3]
SetStores unique values{"Dart", "Flutter"}
MapStores key-value pairs{"name": "Rahul"}
ObjectRepresents a Dart objectObject value = "Hello";
dynamicAllows dynamic typingdynamic value = 10;
NullRepresents the null valuenull

 

3. Strings in Dart

 


    A String represents a sequence of characters and is used for storing text.
    Strings are commonly used for names, messages, addresses, descriptions, URLs, labels,
    and other textual information.
 

 

Creating a String

 

String name = "Rahul";
String city = "Mumbai";
String course = "Flutter Development";

 

Single Quotes

 

String message = 'Hello Dart';

 

Double Quotes

 

String message = "Hello Dart";

 


    Both single and double quotes can be used for ordinary Dart strings.
 

 

4. String Interpolation

 


    String interpolation allows variables and expressions to be inserted directly into a string.
    Dart uses the $ symbol for this purpose.
 

 

String name = "Rahul";
int age = 25;

print("My name is $name");
print("I am $age years old");

 

Output:

 

My name is Rahul
I am 25 years old

 

Using Expressions

 

int price = 500;
int quantity = 3;

print("Total: ${price * quantity}");

 

Output:

 

Total: 1500

 

5. Common String Properties and Methods

 

length

 

String name = "Flutter";

print(name.length);

 

Output:

 

7

 

toUpperCase()

 

String name = "flutter";

print(name.toUpperCase());

 

toLowerCase()

 

String name = "FLUTTER";

print(name.toLowerCase());

 

contains()

 

String course = "Flutter Development";

print(course.contains("Flutter"));

 

trim()

 

String name = "  Rahul  ";

print(name.trim());

 

replaceAll()

 

String text = "Hello Java";

String result = text.replaceAll("Java", "Dart");

print(result);

 

split()

 

String data = "Dart,Flutter,Firebase";

List<String> items = data.split(",");

print(items);

 

6. Multiline Strings

 


    Triple quotes can be used to create multiline strings.
 

 

String message = '''
Welcome to Dart.
Learn Flutter.
Build mobile applications.
''';

print(message);

 

7. Numbers in Dart

 


    Dart provides numeric types for working with numbers. The most commonly used numeric types
    are int, double, and num.
 

 

8. int – Integer Numbers

 


    The int type is used for whole numbers without a fractional part.
 

 

int age = 25;
int students = 100;
int score = 95;
int year = 2026;

 

Arithmetic with int

 

int a = 20;
int b = 10;

print(a + b);
print(a - b);
print(a * b);
print(a ~/ b);
print(a % b);

 


    The ~/ operator performs integer division.
 

 

9. double – Decimal Numbers

 


    The double type is used for numbers that can contain a fractional or decimal
    component.
 

 

double price = 499.99;
double percentage = 85.5;
double temperature = 32.7;

 

Example

 

double price = 499.99;
double discount = 50.50;

double finalPrice = price - discount;

print(finalPrice);

 

10. num – General Numeric Type

 


    The num type can represent both integer and double values.
 

 

num value = 100;

value = 99.50;

print(value);

 


    This is useful when a numeric value may be either an integer or a decimal.
 

 

11. Number Operations

 

Dart supports common arithmetic operations.

 

int a = 20;
int b = 6;

print(a + b);  // Addition
print(a - b);  // Subtraction
print(a * b);  // Multiplication
print(a / b);  // Division
print(a ~/ b); // Integer division
print(a % b);  // Remainder

 

12. Useful Number Methods

 

abs()

 

int number = -25;

print(number.abs());

 

round()

 

double price = 99.60;

print(price.round());

 

floor()

 

double price = 99.90;

print(price.floor());

 

ceil()

 

double price = 99.10;

print(price.ceil());

 

13. Boolean Values in Dart

 


    The bool type represents one of two logical values:
    true or false.
 

 

bool isLoggedIn = true;
bool isAdmin = false;
bool isAvailable = true;

 

Using Boolean Values with if

 

bool isLoggedIn = true;

if (isLoggedIn) {
  print("Welcome to the application");
} else {
  print("Please log in");
}

 

14. Boolean Expressions

 


    Comparison operators produce Boolean values.
 

 

int age = 25;

print(age > 18);
print(age == 25);
print(age != 30);

 

Output:

 

true
true
true

 

15. Logical Operators

 


    Multiple Boolean expressions can be combined using logical operators.
 

 

AND Operator

 

bool isLoggedIn = true;
bool isVerified = true;

bool canAccess = isLoggedIn && isVerified;

print(canAccess);

 

OR Operator

 

bool isAdmin = false;
bool isManager = true;

bool hasPermission = isAdmin || isManager;

print(hasPermission);

 

NOT Operator

 

bool isBlocked = false;

print(!isBlocked);

 

16. Lists in Dart

 


    A List is an ordered collection of values. Lists are commonly used when
    multiple related items need to be stored together.
 

 

List<String> fruits = [
  "Apple",
  "Banana",
  "Mango"
];

 

17. List Indexing

 


    List indexes start from 0.
 

 

List<String> fruits = [
  "Apple",
  "Banana",
  "Mango"
];

print(fruits[0]);
print(fruits[1]);
print(fruits[2]);

 

Output:

 

Apple
Banana
Mango

 

18. Adding Items to a List

 

List<String> fruits = [
  "Apple",
  "Banana"
];

fruits.add("Mango");

print(fruits);

 

19. Removing Items from a List

 

List<String> fruits = [
  "Apple",
  "Banana",
  "Mango"
];

fruits.remove("Banana");

print(fruits);

 

20. List Length

 

List<int> numbers = [10, 20, 30, 40];

print(numbers.length);

 

Output:

 

4

 

21. Looping Through a List

 

List<String> languages = [
  "Dart",
  "Flutter",
  "Java",
  "Python"
];

for (String language in languages) {
  print(language);
}

 

22. List of Numbers

 

List<int> marks = [
  80,
  85,
  90,
  95
];

int total = 0;

for (int mark in marks) {
  total += mark;
}

print("Total: $total");

 

23. List of Objects

 


    Lists can also contain objects created from classes.
 

 

class Student {
  String name;

  Student(this.name);
}

void main() {
  List<Student> students = [
    Student("Rahul"),
    Student("Amit"),
    Student("Priya")
  ];

  for (Student student in students) {
    print(student.name);
  }
}

 

24. Set Data Type

 


    A Set is a collection where each value occurs only once.
 

 

Set<String> skills = {
  "Dart",
  "Flutter",
  "Firebase"
};

 

Adding a Set Value

 

skills.add("REST API");

 

Duplicate Values

 

Set<String> languages = {
  "Dart",
  "Flutter",
  "Dart"
};

print(languages);

 


    The duplicate "Dart" value is not stored as a second distinct element.
 

 

25. Map Data Type

 


    A Map stores information using key-value pairs. Maps are especially useful
    for structured data and JSON-like information.
 

 

Map<String, dynamic> user = {
  "name": "Rahul",
  "age": 25,
  "city": "Mumbai"
};

 

Accessing Map Values

 

print(user["name"]);
print(user["age"]);
print(user["city"]);

 

Adding a New Key-Value Pair

 

user["email"] = "[email protected]";

 

Updating a Value

 

user["age"] = 26;

 

26. Object Data Type

 


    Object is a general Dart type that can represent values that are objects.
 

 

Object value = "Hello";

value = 100;
value = true;

 


    Because the static type is Object, operations specific to a particular
    type may require type checking or casting.
 

 

27. dynamic Data Type

 


    The dynamic type allows a variable to contain values of different types.
 

 

dynamic value = 100;

value = "Hello";

value = true;

print(value);

 


    dynamic can be useful when working with data whose type is not known in advance,
    but unnecessary use can reduce the benefits of Dart's static type checking.
 

 

28. Null and Nullable Types

 


    Dart supports null safety. A normal non-nullable variable cannot contain null.
 

 

String name = "Rahul";

 


    If a value is allowed to be null, add ? to the type.
 

 

String? middleName;

middleName = null;

 

Nullable Number

 

int? age;

age = null;
age = 25;

 

29. final and const

 


    Dart also provides final and const for values that should not
    be reassigned.
 

 

final

 

final String name = "Rahul";

// name = "Amit"; // Invalid

 

const

 

const double pi = 3.14159;
const int maxUsers = 100;

 

30. Difference Between Common Data Types

 


   
     
       
       
       
     
   
   
     
       
       
       
     
     
       
       
       
     
     
       
       
       
     
     
       
       
       
     
     
       
       
       
     
     
       
       
       
     
     
       
       
       
     
     
       
       
       
     
     
       
       
       
     
     
       
       
       
     
     
       
       
       
     
   
 
TypeStoresExample
StringText"Flutter"
intWhole numbers25
doubleDecimal numbers25.50
numNumeric values25 or 25.5
boolLogical valuestrue
ListOrdered collection[1, 2, 3]
SetUnique collection{"A", "B"}
MapKey-value data{"id": 1}
ObjectGeneral Dart objectObject value
dynamicDynamically typed valuesdynamic value
NullAbsence of a valuenull

 

31. Type Inference with var

 


    Dart can infer the type of a variable from its initial value.
 

 

var name = "Rahul";
var age = 25;
var price = 99.99;
var loggedIn = true;

print(name);
print(age);
print(price);
print(loggedIn);

 


    The inferred types are effectively String, int,
    double, and bool.
 

 

32. Generic Lists

 


    Generic type parameters allow you to specify what kind of values a collection should contain.
 

 

List<String> names = [
  "Rahul",
  "Amit",
  "Priya"
];

List<int> ages = [
  20,
  25,
  30
];

 

33. Generic Sets

 

Set<String> technologies = {
  "Dart",
  "Flutter",
  "Firebase"
};

 

34. Generic Maps

 

Map<String, int> marks = {
  "Rahul": 90,
  "Amit": 85,
  "Priya": 95
};

 


    Here, keys are strings and values are integers.
 

 

35. Data Types in Flutter Applications

 


    These Dart data types are used throughout Flutter development. For example, a product model
    may use strings for names, doubles for prices, integers for quantities, Booleans for status,
    and lists for multiple products.
 

 

class Product {
  String name;
  double price;
  int quantity;
  bool isAvailable;

  Product({
    required this.name,
    required this.price,
    required this.quantity,
    required this.isAvailable,
  });
}

 

36. Example: Product List

 

class Product {
  String name;
  double price;

  Product({
    required this.name,
    required this.price,
  });
}

void main() {
  List<Product> products = [
    Product(
      name: "Laptop",
      price: 55000.00,
    ),
    Product(
      name: "Mobile",
      price: 25000.00,
    ),
    Product(
      name: "Headphones",
      price: 2500.00,
    ),
  ];

  for (Product product in products) {
    print("${product.name}: ₹${product.price}");
  }
}

 

37. Example: User Data

 

void main() {
  String name = "Rahul";
  int age = 25;
  double accountBalance = 12500.50;
  bool isVerified = true;

  List<String> skills = [
    "Dart",
    "Flutter",
    "Firebase"
  ];

  Map<String, dynamic> user = {
    "name": name,
    "age": age,
    "balance": accountBalance,
    "verified": isVerified,
    "skills": skills
  };

  print(user);
}

 

38. Strings, Numbers, Booleans, and Collections Together

 

void main() {
  // String
  String studentName = "Rahul";

  // Integer
  int age = 21;

  // Double
  double percentage = 87.5;

  // Boolean
  bool passed = true;

  // List
  List<String> subjects = [
    "Dart",
    "Flutter",
    "Firebase"
  ];

  // Set
  Set<String> skills = {
    "Dart",
    "Flutter",
    "Git"
  };

  // Map
  Map<String, dynamic> student = {
    "name": studentName,
    "age": age,
    "percentage": percentage,
    "passed": passed,
    "subjects": subjects,
    "skills": skills
  };

  print(student);
}

 

39. Choosing the Correct Data Type

 


   
     
       
       
       
     
   
   
     
       
       
       
     
     
       
       
       
     
     
       
       
       
     
     
       
       
       
     
     
       
       
       
     
     
       
       
       
     
     
       
       
       
     
   
 
RequirementRecommended TypeExample
User's nameStringString name = "Rahul";
User's ageintint age = 25;
Product pricedoubledouble price = 999.99;
Login statusboolbool loggedIn = true;
List of productsListList<Product> products = [];
Unique categoriesSetSet<String> categories = {};
User profile key-value dataMapMap<String, dynamic> user = {};

 

40. Common Beginner Mistakes

 

Using the Wrong Data Type

 

Incorrect:

 

int age = "25";

 

Correct:

 

int age = 25;

 

Using a String Instead of a Number

 

For numeric calculations, use numeric types rather than storing the number as text.

 

double price = 499.99;

 

Using Null with a Non-Nullable Type

 

Incorrect:

 

// String name = null;

 

Correct:

 

String? name = null;

 

Unnecessary dynamic

 


    If the type is already known, use a specific type instead of dynamic.
 

 

int age = 25;

 

41. Best Practices

 


       
  • Use descriptive variable names.

  •    
  • Choose the most appropriate data type for each value.

  •    
  • Use String for text.

  •    
  • Use int for whole numbers.

  •    
  • Use double for decimal values.

  •    
  • Use bool for true/false states.

  •    
  • Use List for ordered collections.

  •    
  • Use Set when duplicate values should not be stored.

  •    
  • Use Map for key-value relationships.

  •    
  • Use generic collection types such as List<String> where appropriate.

  •    
  • Use nullable types only when null is a valid state.

  •    
  • Avoid unnecessary use of dynamic.

  •    
  • Use final when a variable should not be reassigned.

  •    
  • Use const for compile-time constant values.

  •  

 

42. Practice Exercises

 


       
  1. Create a String variable containing your full name.

  2.    
  3. Create an integer variable containing your age.

  4.    
  5. Create a double variable containing the price of a product.

  6.    
  7. Create a Boolean variable representing whether you are logged in.

  8.    
  9. Create a List containing five programming languages.

  10.    
  11. Create a List of integers containing five marks.

  12.    
  13. Create a Set containing five unique skills.

  14.    
  15. Create a Map containing a user's name, age, email, and city.

  16.    
  17. Write a program that calculates the total price of three products.

  18.    
  19. Write a program that checks a Boolean login status.

  20.    
  21. Create a list of students using a custom Student class.

  22.    
  23. Create a product model using String, double, int, and bool properties.

  24.  

 

43. Quick Revision

 


       
  • String: Used for text.

  •    
  • int: Used for whole numbers.

  •    
  • double: Used for decimal numbers.

  •    
  • num: Used for numeric values that may be integers or doubles.

  •    
  • bool: Stores true or false.

  •    
  • List: Stores an ordered collection.

  •    
  • Set: Stores unique values.

  •    
  • Map: Stores key-value pairs.

  •    
  • Object: Represents a general Dart object.

  •    
  • dynamic: Allows dynamic typing.

  •    
  • Null: Represents the absence of a value.

  •    
  • ? Makes a type nullable.

  •    
  • final: Allows assignment only once.

  •    
  • const: Represents a compile-time constant.

  •  

 

44. Conclusion

 


    Strings, numbers, Boolean values, lists, sets, maps, and other Dart data types are the
    foundation of data handling in Flutter applications. A strong understanding of these
    types helps developers create models, process user input, handle API responses, manage
    application state, and build dynamic interfaces.
 

 


    JustAcademy's Flutter curriculum specifically includes Dart variables and data types,
    along with List, Set, and Map collections, as part of its Dart Programming Fundamentals
    module. :contentReference[oaicite:1]{index=1}
 

 

Useful JustAcademy Links

 


    Flutter Training:
           target="_blank"
       rel="noopener noreferrer">
      JustAcademy Flutter Training
   

 

 


    Course Demo Registration:
           target="_blank"
       rel="noopener noreferrer">
      Register for Course Demo
   

 


whatsapp