Drawer-Behavior-Flutter icon indicating copy to clipboard operation
Drawer-Behavior-Flutter copied to clipboard

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

Open developerenact opened this issue 5 years ago • 1 comments

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.

developerenact avatar Jun 27 '19 13:06 developerenact

Try replace this,

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

with this one,

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

shiburagi avatar Jul 03 '19 08:07 shiburagi