【发布时间】:2021-08-18 15:50:48
【问题描述】:
当我的 GetX 状态发生变化时,如何调用我的无状态小部件中的特定函数? 例如。每当我的底部导航栏的索引发生变化时,如何触发事件?
Obx(
() =>
BottomNavigationBar(
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.explore),
label: 'Erkunden',
),
],
currentIndex: bottomNavigationController.index.value,
onTap: (index) {
bottomNavigationController.changeIndex(index);
},
)
),
编辑:
class BottomNavigationController extends GetxController {
RxInt index = 0.obs;
void changeIndex(int val) {
index.value = val;
}
}
【问题讨论】:
标签: flutter dart flutter-getx