huextrat / menu_button

Flutter plugin to display a popup menu button widget with handsome design and easy to use.
https://pub.dev/packages/menu_button
MIT License
65 stars 23 forks source link

exceptions on asserts #11

Closed sgehrman closed 4 years ago

sgehrman commented 4 years ago

I was running with "All Exceptions" mode in the VSCode debugger.

These exceptions fail, and you have the same one twice in a row.

In menu_button.dart

44: assert(!dontShowTheSameItemSelected || selectedItem != null), 45: assert(!dontShowTheSameItemSelected || selectedItem != null);

dipcse07 commented 4 years ago

I got the same problem

lucas-sesti commented 4 years ago

Are you using the dontShowTheSameItemSelected? (The default value is true, need to add selectedItem option to the Menu Button if it is true the dontShowTheSameItemSelected)

dipcse07 commented 4 years ago

I am just using only the required values..

On Tue, 16 Jun 2020 at 18:49, Lucas Buchalla Sesti notifications@github.com wrote:

Are you using the dontShowTheSameItemSelected? (The default value is true, need to add selectedItem option to the Menu Button)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/huextrat/menu_button/issues/11#issuecomment-644741314, or unsubscribe https://github.com/notifications/unsubscribe-auth/AESL7ZFWQZLF76JNJAPWDQDRW5S6LANCNFSM4N7PEK7Q .

lucas-sesti commented 4 years ago

Can you show your menu button code?

dipcse07 commented 4 years ago

okay wait a second

dipcse07 commented 4 years ago

@lucas-sesti I have used same code that has given in the How to use section of menu button in pub.dev just to check everything is okay or not.. but its now working.. with those error message

menu button code: MenuButton( child: button,// Widget displayed as the button items: ['button1','button2'],// List of your items topDivider: true, popupHeight: 200, // This popupHeight is optional. The default height is the size of items scrollPhysics: AlwaysScrollableScrollPhysics(), // Change the physics of opened menu (example: you can remove or add scroll to menu) itemBuilder: (value) => Container( width: 83, height: 40, alignment: Alignment.centerLeft, padding: const EdgeInsets.symmetric(horizontal: 16), child: Text(value) ),// Widget displayed for each item toggledChild: Container( color: Colors.white, child: button,// Widget displayed as the button, ), divider: Container( height: 1, color: Colors.grey, ), onItemSelected: (value) { selectedItem = value; // Action when new item is selected }, decoration: BoxDecoration( border: Border.all(color: Colors.grey[300]), borderRadius: const BorderRadius.all(Radius.circular(3.0)), color: Colors.white ), onMenuButtonToggle: (isToggle) { print(isToggle); }, ),

button code:

final Widget button = SizedBox( width: 83, height: 40, child: Padding( padding: const EdgeInsets.only(left: 16, right: 11), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: <Widget>[ Flexible( child: Text( selectedItem, style: TextStyle(color: Colors.yellow), overflow: TextOverflow.ellipsis, ), ), SizedBox( width: 12, height: 17, child: FittedBox( fit: BoxFit.fill, child: Icon( Icons.arrow_drop_down, color: Colors.grey, ) ) ), ], ), ), );

and the error:

flutter: 'package:menu_button/menu_button.dart': Failed assertion: line 45 pos 16: flutter: '!dontShowTheSameItemSelected || selectedItem != null': is not true. flutter: flutter: Either the assertion indicates an error in the framework itself, or we should provide substantially flutter: more information in this error message to help you determine and fix the underlying cause. flutter: In either case, please report this assertion by filing a bug on GitHub: flutter: https://github.com/flutter/flutter/issues/new?template=BUG.md flutter:

huextrat commented 4 years ago

Ok I can reproduce the issue thanks. You'll have to pass selectedItem property to avoid this kind of error.

And on my side there is a modification to do in the library but it will cause breaking change for current user. I'll try to find a better solution to not require selectedItem value

lucas-sesti commented 4 years ago

@huextrat If change the dontShowTheSameItem to default false, its the solution i guess

huextrat commented 4 years ago

@lucas-sesti Yes that what I'm thinking but all the user using dontShowTheSameItem currently will have to pass it to true after the next update :/

huextrat commented 4 years ago

I'm gonna do a new release solving the problem (1.2.0) in the afternoon. Thanks for contribution

huextrat commented 4 years ago

Please upgrade to menu_button: 1.2.0 there is a fix for this issue.