在GETX对话框中使用GETX OBX和GETX状态管理
我在应用程序中使用GET对话框,我想在对话框内部使用GetX状态管理,例如我在对话框内有复选框,并且我想使用GetX更新其状态,但是当我使用getx< appcontroller>( )
在我的获取对话框中,我遇到了以下错误
您只应将getx或obx用于特定的小部件 更新。 如果您看到此错误,您可能没有将任何可观察的变量插入GetX/obx 或将它们插入getx认为适合更新的范围之外 (示例:getx => heidewidget => variable observable)。 如果您需要更新父窗口小部件和子小部件,请将每个小部件包装在OBX/GETX中。 这是示例代码:
Get.dialog(
Dialog(
child: Flexible(
child: GetX<AppController>(
init: appController,
builder: (val){
return CheckboxListTile(
title: Text("Power off computer"),
contentPadding: EdgeInsets.zero,
value: appController.powerOffRaspberry,
onChanged: (newValue) {
appController.powerOffRaspberry = !appController.powerOffRaspberry;
},
controlAffinity: ListTileControlAffinity.leading, // <-- leading Checkbox
);
},
)
),
),
)
I am using Get dialog in my app and I want to use GetX state management inside my dialog widget for example I have checkbox inside my dialog and I want to update it's state with GetX however when I use the GetX<AppController>()
inside my get dialog I ran into following error
You should only use GetX or Obx for the specific widget that will be
updated.
If you are seeing this error, you probably did not insert any observable variables into GetX/Obx
or insert them outside the scope that GetX considers suitable for an update
(example: GetX => HeavyWidget => variableObservable).
If you need to update a parent widget and a child widget, wrap each one in an Obx/GetX.
Here is the sample code:
Get.dialog(
Dialog(
child: Flexible(
child: GetX<AppController>(
init: appController,
builder: (val){
return CheckboxListTile(
title: Text("Power off computer"),
contentPadding: EdgeInsets.zero,
value: appController.powerOffRaspberry,
onChanged: (newValue) {
appController.powerOffRaspberry = !appController.powerOffRaspberry;
},
controlAffinity: ListTileControlAffinity.leading, // <-- leading Checkbox
);
},
)
),
),
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
制作
AppController.poweroffraspberry
可观察:update
chackboxlisttile
as:Make
appController.powerOffRaspberry
observable:Update
CheckboxListTile
as: