@@ -810,6 +810,7 @@ class MenuItemButton extends StatefulWidget {
810
810
this .clipBehavior = Clip .none,
811
811
this .leadingIcon,
812
812
this .trailingIcon,
813
+ this .closeOnActivate = true ,
813
814
required this .child,
814
815
});
815
816
@@ -871,6 +872,14 @@ class MenuItemButton extends StatefulWidget {
871
872
/// An optional icon to display after the [child] label.
872
873
final Widget ? trailingIcon;
873
874
875
+ /// {@template flutter.material.menu_anchor.closeOnActivate}
876
+ /// Determines if the menu will be closed when a [MenuItemButton]
877
+ /// is pressed.
878
+ ///
879
+ /// Defaults to true.
880
+ /// {@endtemplate}
881
+ final bool closeOnActivate;
882
+
874
883
/// The widget displayed in the center of this button.
875
884
///
876
885
/// Typically this is the button's label, using a [Text] widget.
@@ -1089,7 +1098,9 @@ class _MenuItemButtonState extends State<MenuItemButton> {
1089
1098
void _handleSelect () {
1090
1099
assert (_debugMenuInfo ('Selected ${widget .child } menu' ));
1091
1100
widget.onPressed? .call ();
1092
- _MenuAnchorState ._maybeOf (context)? ._root._close ();
1101
+ if (widget.closeOnActivate) {
1102
+ _MenuAnchorState ._maybeOf (context)? ._root._close ();
1103
+ }
1093
1104
}
1094
1105
1095
1106
void _createInternalFocusNodeIfNeeded () {
@@ -1140,6 +1151,7 @@ class CheckboxMenuButton extends StatelessWidget {
1140
1151
this .statesController,
1141
1152
this .clipBehavior = Clip .none,
1142
1153
this .trailingIcon,
1154
+ this .closeOnActivate = true ,
1143
1155
required this .child,
1144
1156
});
1145
1157
@@ -1242,6 +1254,9 @@ class CheckboxMenuButton extends StatelessWidget {
1242
1254
/// An optional icon to display after the [child] label.
1243
1255
final Widget ? trailingIcon;
1244
1256
1257
+ /// {@macro flutter.material.menu_anchor.closeOnActivate}
1258
+ final bool closeOnActivate;
1259
+
1245
1260
/// The widget displayed in the center of this button.
1246
1261
///
1247
1262
/// Typically this is the button's label, using a [Text] widget.
@@ -1292,6 +1307,7 @@ class CheckboxMenuButton extends StatelessWidget {
1292
1307
),
1293
1308
clipBehavior: clipBehavior,
1294
1309
trailingIcon: trailingIcon,
1310
+ closeOnActivate: closeOnActivate,
1295
1311
child: child,
1296
1312
);
1297
1313
}
@@ -1332,6 +1348,7 @@ class RadioMenuButton<T> extends StatelessWidget {
1332
1348
this .statesController,
1333
1349
this .clipBehavior = Clip .none,
1334
1350
this .trailingIcon,
1351
+ this .closeOnActivate = true ,
1335
1352
required this .child,
1336
1353
});
1337
1354
@@ -1436,6 +1453,9 @@ class RadioMenuButton<T> extends StatelessWidget {
1436
1453
/// An optional icon to display after the [child] label.
1437
1454
final Widget ? trailingIcon;
1438
1455
1456
+ /// {@macro flutter.material.menu_anchor.closeOnActivate}
1457
+ final bool closeOnActivate;
1458
+
1439
1459
/// The widget displayed in the center of this button.
1440
1460
///
1441
1461
/// Typically this is the button's label, using a [Text] widget.
@@ -1483,6 +1503,7 @@ class RadioMenuButton<T> extends StatelessWidget {
1483
1503
),
1484
1504
clipBehavior: clipBehavior,
1485
1505
trailingIcon: trailingIcon,
1506
+ closeOnActivate: closeOnActivate,
1486
1507
child: child,
1487
1508
);
1488
1509
}
0 commit comments