Conversation
ef1f3ec to
c992679
Compare
|
Hans told me you got a lot on your plate. I'll help finish with this. I'll push commits to this draft. |
Thanks so much for the help! Really appreciated! Currently for this PR, I think it can fix the issues it links, but some problems still happen. Please try to run some |
|
@QuncCccccc |
Ah interesting. Let me have a quick look. It's been a while that I didn't work on this issue. |
|
Basically this code sampleimport 'package:flutter/material.dart';
import 'package:flutter/services.dart';
/// Flutter code sample for [MenuAcceleratorLabel].
void main() => runApp(const MenuAcceleratorApp());
class MyMenuBar extends StatelessWidget {
const MyMenuBar({super.key});
@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
MenuBar(
children: <Widget>[
MenuItemButton(
// menuDirection: Axis.horizontal,
onPressed: () {
showAboutDialog(
context: context,
applicationName: 'MenuBar Sample',
applicationVersion: '1.0.0',
);
},
child: Text('&About'),
),
// SubmenuButton(
// menuChildren: <Widget>[
// // MenuItemButton(
// // onPressed: () {
// // showAboutDialog(
// // context: context,
// // applicationName: 'MenuBar Sample',
// // applicationVersion: '1.0.0',
// // );
// // },
// // child: Text('&About'),
// // ),
// // MenuItemButton(
// // onPressed: () {
// // ScaffoldMessenger.of(context).showSnackBar(
// // const SnackBar(
// // content: Text('Saved!'),
// // ),
// // );
// // },
// // child: Text('&Save'),
// // ),
// // MenuItemButton(
// // onPressed: () {
// // ScaffoldMessenger.of(context).showSnackBar(
// // const SnackBar(
// // content: Text('Quit!'),
// // ),
// // );
// // },
// // child: Text('&Quit'),
// // ),
// ],
// child: Text('&File'),
// ),
// SubmenuButton(
// menuChildren: <Widget>[
// // MenuItemButton(
// // onPressed: () {
// // ScaffoldMessenger.of(context).showSnackBar(
// // const SnackBar(
// // content: Text('Magnify!'),
// // ),
// // );
// // },
// // child: Text('&Magnify'),
// // ),
// // MenuItemButton(
// // onPressed: () {
// // ScaffoldMessenger.of(context).showSnackBar(
// // const SnackBar(
// // content: Text('Minify!'),
// // ),
// // );
// // },
// // child: Text('Mi&nify'),
// // ),
// ],
// child: Text('&View'),
// ),
],
),
],
),
Expanded(
child: FlutterLogo(
size: MediaQuery.of(context).size.shortestSide * 0.5,
),
),
],
);
}
}
class MenuAcceleratorApp extends StatelessWidget {
const MenuAcceleratorApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(useMaterial3: true),
home: Shortcuts(
shortcuts: <ShortcutActivator, Intent>{
const SingleActivator(LogicalKeyboardKey.keyT, control: true): VoidCallbackIntent(() {
debugDumpApp();
}),
},
child: const Scaffold(body: MyMenuBar()),
),
);
}
}
|
|
I can see the issue. Thanks for the details. Since this PR has conflicts and some challenges in order to land this. I'll close this PR then investigate the problem, write tests, and file a PR myself. |
fixes [MenuItemButton does not constrain its child](#129439) fixes [DropdownMenuEntry Text Overflow when width of DropdownMenu is not specified](#140596) ### Description - This PR continues the fix from #141314 (comment) and adds controlled widths for the `MenuBar` children to fix the unbounded width issue which blocked the PR earlier. (Widgets with non-zero flex value cannot be laid out in a horizontal scroll view which is created by `MenuBar` widget) - Added tests coverage. - Added documentation. ### Code sample <details> <summary>expand to view the code sample</summary> ```dart import 'package:flutter/material.dart'; void main() => runApp(const MyApp()); class MyApp extends StatefulWidget { const MyApp({super.key}); @OverRide State<MyApp> createState() => _MyAppState(); } class _MyAppState extends State<MyApp> { MenuController menuController = MenuController(); @OverRide Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, home: Scaffold( body: Padding( padding: const EdgeInsets.all(16.0), child: Column( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ DropdownMenu<int>( expandedInsets: EdgeInsets.zero, dropdownMenuEntries: <DropdownMenuEntry<int>>[ DropdownMenuEntry<int>( value: 0, label: 'This is a long text that is multiplied by 10. ' * 10, style: const ButtonStyle( textStyle: MaterialStatePropertyAll( TextStyle(overflow: TextOverflow.ellipsis), ), ), ), ], ), SizedBox( width: 200, child: MenuItemButton( onPressed: () {}, leadingIcon: const Icon(Icons.menu), trailingIcon: const Icon(Icons.arrow_forward_ios), child: const Text( 'This is a very long text that will wrap to the multiple lines.', maxLines: 1, overflow: TextOverflow.ellipsis, ), ), ), // MenuBar( // children: [ // MenuItemButton( // onPressed: () { // }, // child: Text('Short Text Menu'), // ), // MenuItemButton( // onPressed: () {}, // child: Text('Very very very very very long text menu'), // ), // ], // ), ], ), ), ), ); } } ``` </details> ### Before  ### After 
Fixes #129439 and #140596
This PR is to fix the overflow issue when the menu item contains long content in
MenuItemButtonandDropdownMenu.Before:

After:

Pre-launch Checklist
///).