How to set enum variable observable?

Viewed 1721

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

1 Answers

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}');
Related