I had the same problem in one of my projects and the existing solutions were not very clean and it did not support advanced features like json serialization / deserialization.
Flutter did not initially support enum with values, however I managed to develop a Vnum helper package using a class implementation and reflectors to solve this problem.
Contact the repository:
https://github.com/AmirKamali/Flutter_Vnum
To answer your problem with Vnum , you can implement your code like Vnum below:
@VnumDefinition class Visibility extends Vnum<String> { static const VISIBLE = const Visibility.define("VISIBLE"); static const COLLAPSED = const Visibility.define("COLLAPSED"); static const HIDDEN = const Visibility.define("HIDDEN"); const Visibility.define(String fromValue) : super.define(fromValue); factory Visibility(String value) => Vnum.fromValue(value,Visibility); }
You can use it like:
var visibility = Visibility('COLLAPSED'); print(visibility.value);
The github repository has more documentation, hope it helps you.
source share