类型

  1. Numbers (数字类型)

    • int (整型)
    • double (浮点型)
  2. Strings (字符串类型)

  3. Booleans (布尔类型)

  4. Lists (列表类型)

  5. Maps (映射类型)

  6. Sets (集合类型)

  7. Dynamic type (动态类型)

  8. Object type (对象类型)

  9. Function type (函数类型)

示例

// Numbers
int age = 25;
double height = 5.8;
 
// Strings
String name = "John Doe";
 
// Booleans
bool isStudent = true;
 
// Lists
List<int> numbers = [1, 2, 3, 4, 5];
 
// Maps
Map<String, dynamic> person = {
  'name': 'Alice',
  'age': 30,
};
 
// Sets
Set<String> fruits = {'apple', 'banana', 'orange'};
 
// Dynamic type
dynamic value = "Hello";
 
// Object type
Object obj = {'key': 'value'};
 
// Function type
void greet(String name) {
  print("Hello $name!");
}
 
greet("Alice");

在 Dart 中,每种数据类型都有其特定用途和功能。通过了解这些数据类型,您可以更好地编写清晰、高效的代码。