小编Phi*_*ipp的帖子

Dart:为什么继承的字段不能用作构造函数参数?

以下代码将不会运行:

class X{
 double? x;
}

mixin Y{
 double? y;
}

class Z extends X with Y {
 double? z; 
 Z(this.x, this.y, this.z)
}
Run Code Online (Sandbox Code Playgroud)

编译器会抱怨 this.x 和 this.y 不是封闭类中的字段:

lib/physicalObject.dart:20:10: Error: 'x' isn't an instance field of this class.
Z(this.x, this.y, this.z)
     ^

lib/physicalObject.dart:20:18: Error: 'y' isn't an instance field of this class.
Z(this.x, this.y, this.z)
             ^
Run Code Online (Sandbox Code Playgroud)

当然这不是真的,字段x和y是从父类和mixin继承的。我可以在子类 Z 中使用这些字段,似乎只有构造函数在接受这些字段作为参数时存在问题。但为什么?

inheritance mixins dart

5
推荐指数
1
解决办法
1563
查看次数

Flutter:我能知道我在哪个平台吗?

我正在开发一个项目,该项目既可以作为应用程序也可以作为网页使用。我正在使用 flutter_secure_storage 来存储应用程序的本地数据,但我需要一种不同的网络方法。有没有办法可以在运行时找出我所在的平台,并相应地选择正确的读写函数?

flutter flutter-web

4
推荐指数
1
解决办法
5717
查看次数

标签 统计

dart ×1

flutter ×1

flutter-web ×1

inheritance ×1

mixins ×1