flutter - 为什么我们应该在飞镖中使用静态关键字来代替抽象?
问题描述
我正在我的flutterfire项目中准备一个课程,他们我想使用一些无法进一步更改的方法,以便我想知道 Dart 中 static 关键字的概念?
解决方案
“静态”表示成员在类本身而不是类的实例上可用。这就是它的全部含义,它不用于其他任何事情。static 修改成员。
静态方法 静态方法(类方法)不对实例进行操作,因此无权访问它。但是,它们确实可以访问静态变量。
void main() {
print(Car.numberOfWheels); //here we use a static variable.
// print(Car.name); // this gives an error we can not access this property without creating an instance of Car class.
print(Car.startCar());//here we use a static method.
Car car = Car();
car.name = 'Honda';
print(car.name);
}
class Car{
static const numberOfWheels =4;
Car({this.name});
String name;
// Static method
static startCar(){
return 'Car is starting';
}
}
推荐阅读
- amazon-cloudfront - CloudFront Origin 基本授权
- php - 为数据库中的每个结果提供不同的链接 - PHP
- java - 如何正确截屏Android设备?
- jquery - jquery滚动到数据图像ID
- android - 重新创建活动后增加内存消耗
- graphviz - 如何在不改变安排的情况下将交易对手 B 连接到 C 以及反之亦然
- javascript - 函数 .data() 不读取内容 onCreate FIrebase 云触发器
- ansible - 如何从 Ansible 连接到 Rally
- excel - 是否有一个 Excel 公式可以返回一个时间范围内的日历月数?
- linux - 从 uart 读取