gpt4 book ai didi

flutter - 在 Flutter 中,如何在较大的屏幕尺寸上修复 PopupMenuItem Widget 中的截断文本?

转载 作者:行者123 更新时间:2023-12-03 02:48:42 25 4
gpt4 key购买 nike

在下面的屏幕截图中,存在一个 UI 崩溃,其中 PopupMenuItem 文本在较大的屏幕尺寸下被截断,但在较窄的屏幕上完全可见。

解决此错误的最佳方法是什么?

运行下面的代码,至少我希望与屏幕截图显示的相反。

据我所知,我没有指定任何宽度限制。

代码设置了独特的颜色背景以指示哪个小部件占用的空间。

enter image description here

import 'package:flutter/material.dart';

main() {
runApp(Main2DemoApp());
}

class Main2DemoApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Main2DemoScreen(),
);
}
}

class Main2DemoScreen extends StatefulWidget {
@override
_Main2DemoState createState() => _Main2DemoState();
}

class _Main2DemoState extends State<Main2DemoScreen> {
static const int EMAIL_CONVERSATION = 11;

AppScale _scale;

@override
Widget build(BuildContext context) {
_scale = AppScale(context);

Widget fullHeaderRow = Row(
children: <Widget>[
Container(
color: Colors.purple[200],
child: getPopupMenuButton(),
),
],
);

fullHeaderRow = Container(
color: Colors.amber[200],
child: fullHeaderRow,
);

return Scaffold(
appBar: AppBar(title: Text('PopupMenuButton Demo')),
body: fullHeaderRow,
);
}

Widget getPopupMenuButton() {
Widget emailPopUpItem = PopupMenuItem(
textStyle: TextStyle(
color: Colors.white,
fontSize: _scale.popupMenuItem,
),
child: Row(
children: [
Padding(
padding: EdgeInsets.only(right: 10),
child: Icon(
Icons.email,
color: Colors.white,
size: _scale.popupMenuItem,
)),
Text('Send Email Message Now')
],
),
value: EMAIL_CONVERSATION,
);

List<PopupMenuEntry<dynamic>> menuWidgets = [emailPopUpItem];
double iconSize = _scale.popupMenuButton;

PopupMenuButton popupMenuButton = PopupMenuButton(
padding: EdgeInsets.all(0),
color: Colors.lightGreen[700],
offset: Offset(40, 20),
shape: RoundedRectangleBorder(borderRadius: new BorderRadius.circular(5)),
icon: Icon(
Icons.more_vert,
color: Colors.white,
size: iconSize,
),
onSelected: (newValue) {
print('newValue: $newValue');
},
itemBuilder: (context) => menuWidgets,
);

return popupMenuButton;
}
}

class AppScale {
BuildContext _ctxt;

AppScale(this._ctxt);

double get popupMenuButton => scaledWidth(.08);
double get popupMenuItem => scaledHeight(.025);

double scaledWidth(double widthScale) {
return MediaQuery.of(_ctxt).size.width * widthScale;
}

double scaledHeight(double heightScale) {
return MediaQuery.of(_ctxt).size.height * heightScale;
}
}

最佳答案

弹出菜单的最大和最小宽度限制在这里定义:popup_menu.dart:554而且好像是不可配置的

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

关于flutter - 在 Flutter 中,如何在较大的屏幕尺寸上修复 PopupMenuItem Widget 中的截断文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63570199/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com