我的代码是这样的
我希望使项目宽度与父项匹配,但无法更改PopupMenuItem宽度我尝试文本换行继续和设置宽度准确,但它不工作。我该怎么办呢?
8ulbf1ek1#
容器内有弹出菜单项
new PopupMenuButton<Choice>( onSelected: _select, itemBuilder: (BuildContext context) { return choices.map((Choice choice) { return PopupMenuItem<Choice>( value: choice, child: new Container( width: 100.0, child: Text(choice.title) ), ); }).toList(); }, ),
完整示例的其他代码
void _select(Choice choice) { print(choice); } class Choice { const Choice({this.title, this.icon}); final String title; final IconData icon; } const List<Choice> choices = const <Choice>[ const Choice(title: 'Car', icon: Icons.directions_car), const Choice(title: 'Bicycle', icon: Icons.directions_bike), const Choice(title: 'Boat', icon: Icons.directions_boat), const Choice(title: 'Bus', icon: Icons.directions_bus), const Choice(title: 'Train', icon: Icons.directions_railway), const Choice(title: 'Walk', icon: Icons.directions_walk), ];
t30tvxxf2#
更改约束中maxWidth的值样本代码
Widget _offsetPopup() => PopupMenuButton<int>( constraints: BoxConstraints( minWidth: 2.0 * 56.0, maxWidth: MediaQuery.of(context).size.width, ), itemBuilder: (context) => [ PopupMenuItem( value: 1, child: Container( width: MediaQuery.of(context).size.width, child: Expanded( child: Text( "To Receive", style: TextStyle( fontSize: 16, color: Colors.black, fontWeight: FontWeight.w700), ), ), ), ), ], icon: Icon(Icons.add), offset: Offset(0, 40));
jexiocij3#
PopupMenuButton提供了设置框约束的选项。您可以使用相同的选项。https://api.flutter.dev/flutter/material/PopupMenuButton/constraints.html
3条答案
按热度按时间8ulbf1ek1#
容器内有弹出菜单项
完整示例的其他代码
t30tvxxf2#
更改约束中maxWidth的值
样本代码
jexiocij3#
PopupMenuButton提供了设置框约束的选项。您可以使用相同的选项。
https://api.flutter.dev/flutter/material/PopupMenuButton/constraints.html