2

请帮助。我使用颤振和GetX。如何设置枚举变量可观察?enum MyEnumType {open,close}; var _myEnumTypeVar = MyEnumType.open.obs;

4

1 回答 1

2

我认为您可以使用Rx带有 Type 参数的构造函数:

class EnumX extends GetxController {
  Rx<MyEnum> myEnum = Rx<MyEnum>(MyEnum.open);
}

enum MyEnum {
  open,
  close
}

将枚举用于@chichi 评论/问题的示例:

    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}');
于 2021-03-03T21:07:58.560 回答