3

Please help.I use flutter and GetX. How to set enum variable observaible? enum MyEnumType {open,close}; var _myEnumTypeVar = MyEnumType.open.obs;

user1942979
  • 119
  • 1
  • 2
  • 6

1 Answers1

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