- child::泛型
类型
-
Numbers (数字类型)
- int (整型)
- double (浮点型)
-
Strings (字符串类型)
-
Booleans (布尔类型)
-
Lists (列表类型)
-
Maps (映射类型)
-
Sets (集合类型)
-
Dynamic type (动态类型)
-
Object type (对象类型)
-
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 中,每种数据类型都有其特定用途和功能。通过了解这些数据类型,您可以更好地编写清晰、高效的代码。