shiburagi / Drawer-Behavior-Flutter

Drawer behavior is a library that provide an extra behavior on drawer, such as, move view or scaling view's height while drawer on slide.
MIT License
209 stars 36 forks source link

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

Open developerenact opened 5 years ago

developerenact commented 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.

shiburagi commented 5 years ago

Try replace this,

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

with this one,

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