我需要一种方法来获取类的属性,因为我知道这是通过反射实现的,但我不知道如何将其应用于 Flutter。
这是我的课:
class Login {
final String name;
final String email;
final String token;
final String refreshToken;
final String createdAt;
final String expiresAt;
final bool isValid;
Login({this.name, this.email, this.token, this.refreshToken, this.createdAt, this.expiresAt, this.isValid});
}
而且我必须做一些像 getOwnProperties 这样的事情,就像在 JS 中完成的那样。 我需要获取类所具有的属性的数组。
最佳答案
Flutter 中没有可用的反射。您可以使用代码生成,例如 reflectable使用 https://pub.dartlang.org/packages/build 打包或自定义生成
关于reflection - 获取类属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52431355/