Dart Data Types: Built in Data Types

Dart Data Types: Built in Data Types

Dart has a variety of built-in data types that you can use to define variables. Here are some of the common built-in data types in Dart:

  1. Numbers:

    • int: Represents integers (whole numbers), both positive and negative.

        int age = 25;
      
    • double: Represents floating-point numbers (numbers with decimal points).

        double height = 1.75;
      
  2. Strings:

    • String: Represents a sequence of characters.

        String name = 'John';
      
  3. Booleans:

    • bool: Represents a boolean value (true or false).

        bool isStudent = true;
      
  4. Lists:

    • List: Represents an ordered collection of elements.

        List<int> numbers = [1, 2, 3, 4, 5];
      
  5. Sets:

    • Set: Represents an unordered collection of unique elements.

        Set<String> uniqueNames = {'Alice', 'Bob', 'Charlie'};
      
  6. Maps:

    • Map: Represents a collection of key-value pairs.

        Map<String, dynamic> person = {
          'name': 'John',
          'age': 25,
          'isStudent': false,
        };
      
  7. Runes:

    • Runes: Represents a sequence of Unicode code points.

        Runes heart = Runes('\u2665');
      
  8. Symbols:

    • Symbol: Represents an operator or identifier that is unique and constant.

        Symbol symbol = #mySymbol;
      
  9. Dynamic:

    • dynamic: Represents a variable with dynamic typing. The type can change at runtime.

        dynamic dynamicVariable = 'Hello';
      
  10. Object:

    • Object: The most general type in Dart. All types are subtypes of Object.

        Object obj = 'Some value';
      

These built-in data types provide flexibility and support for various kinds of values and structures in Dart programming. It's essential to choose the appropriate data type based on the nature of the data you are working with to ensure type safety and efficient code execution.