我有控制器呼叫MenuController
class MenuController extends GetxController {
var currentCategory = Rx<int>(0);
@override
void onReady() async {
await Future.delayed(const Duration(milliseconds: 2000));
}
void setMenuByIndex(int index) {
currentCategory.value = index;
}
}
我正在嘗試從這樣的簡單小部件中檢查選定的索引
Obx(() => Text(controller.currentCategory.value.toString()))
像這里一樣獲取控制器
final controller = Get.find<MenuController>();
我收到錯誤
type 'int' is not a subtype of type 'Rx<int>' of 'function result'
uj5u.com熱心網友回復:
試試這個...
class MenuController extends GetxController {
Rx<int> currentCategory = Rx<int>(0);
@override
void onReady() async {
await Future.delayed(const Duration(milliseconds: 2000));
}
void setMenuByIndex(int index) {
currentCategory.value = index;
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/480541.html
下一篇:返回列表