有没有一种简单的方法将整数值转换为枚举类型?我想从共享首选项中检索整数值并将其转换为枚举类型。
我的枚举类型是:
enum ThemeColor { red, gree, blue, orange, pink, white, black };
我想轻松将整数转换为枚举:
final prefs = await SharedPreferences.getInstance();
ThemeColor c = ThemeColor.convert(prefs.getInt('theme_color')); // something like that
status
是一个枚举类型,你可以使用status.index
来获取整数值。 - maganap