以下代码将不会运行:
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 中使用这些字段,似乎只有构造函数在接受这些字段作为参数时存在问题。但为什么?
我正在开发一个项目,该项目既可以作为应用程序也可以作为网页使用。我正在使用 flutter_secure_storage 来存储应用程序的本地数据,但我需要一种不同的网络方法。有没有办法可以在运行时找出我所在的平台,并相应地选择正确的读写函数?