Please help.I use flutter and GetX.
How to set enum variable observaible? enum MyEnumType {open,close}; var _myEnumTypeVar = MyEnumType.open.obs;
Asked
Active
Viewed 2,711 times
3

user1942979
- 119
- 1
- 2
- 6
1 Answers
4
I think you can use the Rx
constructor with Type parameter:
class EnumX extends GetxController {
Rx<MyEnum> myEnum = Rx<MyEnum>(MyEnum.open);
}
enum MyEnum {
open,
close
}
Example for using enum for @chichi comment/question:
EnumX ex = Get.put(EnumX());
print('enum: ${ex.myEnum.value}');
ex.myEnum(MyEnum.close);
//ex.myEnum.value = MyEnum.close; ← same as this
print('enum: ${ex.myEnum.value}');

Baker
- 24,730
- 11
- 100
- 106
-
How can I update this enum with? `EnumX.myEnum(close) ` seems not working – chichi Sep 24 '21 at 18:17
-
myEnum.value = MyEnum.close; -> this will notify the Obx observables on the UI – Syed Waleed Sep 07 '22 at 19:34