我正在尝试升级我的代码,以使用dart 2.17和flutter 3.0.5的新增强枚举功能。
这是我的列举:
enum Permission {
first(1, "first"),
second(2, "second");
const Permission(this.id, this.name);
final int id;
final String name;
}
用法,在有状态小部件的build((中调用:
String name = Permission.first.name;
当我运行我的程序时,所有的东西都会编译,我没有收到错误消息,但程序挂在白色屏幕上,不断地重新加载,从来没有进入主屏幕。如果我注释掉访问权限名称的行,则所有内容都会正确加载和运行。不确定访问枚举属性导致程序中断的原因。发生这种情况的原因是什么?
不要将name
用作枚举上的文件。它在枚举上已经具有.name
扩展名。
enum Permission {
first(1, "first"),
second(2, "second");
const Permission(this.id, this.value);
final int id;
final String value; //change it to something else
}
现在flutter clean
并重新构建应用程序。
它可能与Flutter中的这个错误有关,应该在下一个版本中修复:https://github.com/flutter/flutter/issues/103656