Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An improper use of GetX has been detected when building PopupMenuButton in Obx #3119

Open
jmgaooo opened this issue Jun 5, 2024 · 0 comments
Assignees

Comments

@jmgaooo
Copy link

jmgaooo commented Jun 5, 2024

[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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants