Open developerenact opened 5 years ago
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.
Try replace this,
onMenuItemSelected: (String itemId) { selectedMenuItemId = itemId; },
with this one,
onMenuItemSelected: (String itemId) { setState(()=>selectedMenuItemId = itemId); },
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.