getx
getx copied to clipboard
An improper use of GetX has been detected when building PopupMenuButton in Obx
[Get] the improper use of a GetX has been detected. You should only use GetX or Obx for the specific widget that will be updated.
//controller
var status= 0.obs;
//widget
Obx(()=>PopupMenuButton<int>(
onSelected: (int item) {
},
itemBuilder: (BuildContext context) => <PopupMenuEntry<int>>[
if(status.value==0)
const PopupMenuItem<int>(
value: 0,
child: Text('Item 1'),
)
else
const PopupMenuItem<int>(
value: 1,
child: Text('Item 2'),
)
],
))
Steps to reproduce the behavior: Supplement the code above and then run it.
Flutter Version: 3.19.6
Getx Version: 4.6.1
Describe on which device you found the bug: any
I know the reason for the error is that the obs value is not accessed internally in obx. I want to know how to use Obx and PopupMenuButton together? Because itemBuilder must return a list of PopupMenuEntry, and Obx cannot be placed here, only outside. But now there is an error, is there a good solution?