颤动 - 中心溢出文本和剪辑
flutter - center overflowing text and clip
实现 layout-design 我正在尝试居中并溢出(剪辑)屏幕外的文本(见图)。红色矩形内的剪辑超出了屏幕,应进行剪辑。
我已经可以让文字溢出屏幕了:
Widget build(BuildContext context) {
return Padding(
padding: EdgeInsets.fromLTRB(0, 50, 0, 30),
child: Text(
"DASHBOARDasdasdasdasdasdasdas",
overflow: TextOverflow.clip,
softWrap: false,
maxLines: 1,
textAlign: TextAlign.center,),
);
}
但我无法将文本居中:
有人知道如何实现这一点吗?
谢谢
更新:
感谢@pungjunghyeon 的回答,文本现在左右溢出了。现在我想剪辑 UnconstrainedBox 以防止溢出警告,但我无法避免它们。关于这一点还有进一步的提示吗?
@override
Widget build(BuildContext context) {
return Container(
width: MediaQuery.of(context).size.width,
child: ClipRect(
child: UnconstrainedBox(
child: Text(
"DASHBOARD",
overflow: TextOverflow.visible,
textAlign: TextAlign.center,
style: TextStyle(
fontFamily: 'Segoe UI',
fontWeight: FontWeight.bold,
fontSize: 60,
letterSpacing: 20,
color: Colors.orange
),
),
),
),
);
}
请使用 UnconstrainedBox 小部件。
例如:
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: appBar,
body: Container(
width: MediaQuery.of(context).size.width,
child: UnconstrainedBox(
child: Text(
'DASHBOARD',
style: TextStyle(fontSize: 80.0),
overflow: TextOverflow.visible,
textAlign: TextAlign.center
),
)
), //Container
); // Scaffold
}
Padding(
padding: EdgeInsets.fromLTRB(0, 50, 0, 30),
child: FittedBox(
fit:BoxFit.contain,
child: Text(
"DASHBOARDasdasdasdasdasdasdas DASHBOARDasdasdasdasdasdasdas DASHBOARDasdasdasdasdasdasdas DASHBOARDasdasdasdasdasdasdas DASHBOARDasdasdasdasdasdasdas DASHBOARDasdasdasdasdasdasdas",
overflow: TextOverflow.clip,
softWrap: false,
maxLines: 1,
textAlign: TextAlign.center,),
),
);
实现 layout-design 我正在尝试居中并溢出(剪辑)屏幕外的文本(见图)。红色矩形内的剪辑超出了屏幕,应进行剪辑。
我已经可以让文字溢出屏幕了:
Widget build(BuildContext context) {
return Padding(
padding: EdgeInsets.fromLTRB(0, 50, 0, 30),
child: Text(
"DASHBOARDasdasdasdasdasdasdas",
overflow: TextOverflow.clip,
softWrap: false,
maxLines: 1,
textAlign: TextAlign.center,),
);
}
但我无法将文本居中:
有人知道如何实现这一点吗?
谢谢
更新:
感谢@pungjunghyeon 的回答,文本现在左右溢出了。现在我想剪辑 UnconstrainedBox 以防止溢出警告,但我无法避免它们。关于这一点还有进一步的提示吗?
@override
Widget build(BuildContext context) {
return Container(
width: MediaQuery.of(context).size.width,
child: ClipRect(
child: UnconstrainedBox(
child: Text(
"DASHBOARD",
overflow: TextOverflow.visible,
textAlign: TextAlign.center,
style: TextStyle(
fontFamily: 'Segoe UI',
fontWeight: FontWeight.bold,
fontSize: 60,
letterSpacing: 20,
color: Colors.orange
),
),
),
),
);
}
请使用 UnconstrainedBox 小部件。
例如:
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: appBar,
body: Container(
width: MediaQuery.of(context).size.width,
child: UnconstrainedBox(
child: Text(
'DASHBOARD',
style: TextStyle(fontSize: 80.0),
overflow: TextOverflow.visible,
textAlign: TextAlign.center
),
)
), //Container
); // Scaffold
}
Padding(
padding: EdgeInsets.fromLTRB(0, 50, 0, 30),
child: FittedBox(
fit:BoxFit.contain,
child: Text(
"DASHBOARDasdasdasdasdasdasdas DASHBOARDasdasdasdasdasdasdas DASHBOARDasdasdasdasdasdasdas DASHBOARDasdasdasdasdasdasdas DASHBOARDasdasdasdasdasdasdas DASHBOARDasdasdasdasdasdasdas",
overflow: TextOverflow.clip,
softWrap: false,
maxLines: 1,
textAlign: TextAlign.center,),
),
);