I am trying to upgrade my code to use the new enhanced enum feature of dart 2.17 and flutter 3.0.5.
Here is my enum:
enum Permission {
first(1, "first"),
second(2, "second");
const Permission(this.id, this.name);
final int id;
final String name;
}
Usage, called in build() of a stateful widget:
String name = Permission.first.name;
When I run my program everything compiles and I get no error messages, but the program hangs on a white screen and constantly reloads, never making it to the home screen. If I comment out the line where I access the name of the permission, everything loads and runs properly. Not sure why accessing the enum property causes the program to break. Any reason this is happening?
CodePudding user response:
Don't use name
as a filed on enum. It is already having a .name
extension on enum.
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
}
Now flutter clean
and rebuild the app.
CodePudding user response:
It can be related to this bug in Flutter that should be fixed in the next versions: https://github.com/flutter/flutter/issues/103656