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

itemBuilder Method always return isSelected "true" from first position. #5

Open
developerenact opened this issue Jun 27, 2019 · 1 comment
Labels
question Further information is requested

Comments

@developerenact
Copy link

I am using you this function:

itemBuilder:
(BuildContext context, MenuItem menuItem, bool isSelected) {
return Container(
color: isSelected
? Theme.of(context).accentColor.withOpacity(0.7)
: Colors.transparent,
padding: EdgeInsets.fromLTRB(24, 16, 24, 16),
child: Text(
menuItem.title,
style: Theme.of(context).textTheme.subhead.copyWith(
color: isSelected ? Colors.black87 : Colors.white70),
),
);
}

But isSelected is always return true for the only first position even I am updating the "selectedMenuItemId".

Here is the whole code for the menu:

menuView: MenuView(
menu: menu,
headerView: headerView(context),
animation: false,
alignment: Alignment.topLeft,
color: Theme.of(context).primaryColor,
selectedItemId: selectedMenuItemId,
onMenuItemSelected: (String itemId) {
selectedMenuItemId = itemId;
},
itemBuilder:
(BuildContext context, MenuItem menuItem, bool isSelected) {
return Container(
color: isSelected
? Theme.of(context).accentColor.withOpacity(0.7)
: Colors.transparent,
padding: EdgeInsets.fromLTRB(24, 16, 24, 16),
child: Text(
menuItem.title,
style: Theme.of(context).textTheme.subhead.copyWith(
color: isSelected ? Colors.black87 : Colors.white70),
),
);
}),

Please let me know how fix it.

@shiburagi
Copy link
Owner

Try replace this,

onMenuItemSelected: (String itemId) {
    selectedMenuItemId = itemId;
},

with this one,

onMenuItemSelected: (String itemId) {
    setState(()=>selectedMenuItemId = itemId);
},

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

No branches or pull requests

2 participants