why constraint PopupMenu's min width?

1,892 views
Skip to first unread message

carmen che

unread,
May 2, 2020, 9:36:44 AM5/2/20
to Flutter Development (flutter-dev)
Hi, everyone,

recently i work on creating a popup menu, but seems the default popup menu created by showMenu() function is too wide, it is not what i want. 
by tracking the source code, I find the following in popup_menu.dart:

const double _kMenuMaxWidth = 5.0 * _kMenuWidthStep;
const double _kMenuMinWidth = 2.0 * _kMenuWidthStep;
const double _kMenuVerticalPadding = 8.0;
const double _kMenuWidthStep = 56.0;
...
...
class _PopupMenu<T> extends StatelessWidget {
    final Widget child = ConstrainedBox(
      constraints: const BoxConstraints(
        minWidth: _kMenuMinWidth,
        maxWidth: _kMenuMaxWidth,
      ),
...
...
}

it constraints popup menu's min width to 2.0 x 56.0, max width to 5.0 x 56.0.

so if i want to customize  popup menu's width outside of the flutter source code, what should I do? if there are any ways to implement this?
btw, why set these constraints to popup menu?

Souvik Dutta

unread,
May 2, 2020, 10:51:01 AM5/2/20
to carmen che, Flutter Development (flutter-dev)
Probably using a constrained box as a parent to the popup widget.

Souvik flutter dev

--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/9b8efa90-3e76-4cfd-a02f-90d5069e0dea%40googlegroups.com.

carmen che

unread,
May 2, 2020, 10:31:52 PM5/2/20
to Flutter Development (flutter-dev)
Thanks Souvik for your reply.
but as i know, if there are 2 constrained boxs as parents, it will apply to the one which minWidth or minHeight is bigger, it is exactly not what i want, well, i wanna make popup menu  width smaller than what constraint in flutter.
also, i am using showMenu(), it returns a Future value, not a widget, so it is not easy to wrap pupup menu widget with  constrained box.

Souvik Dutta

unread,
May 2, 2020, 11:11:49 PM5/2/20
to carmen che, Flutter Development (flutter-dev)
Oh then I guess you should make changes in the package to suit your needs. 

Souvik flutter dev

--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages