随着文本的增长,我想要包装文本.我搜索并尝试用几乎所有东西包裹,但仍然文本保持一行并从屏幕溢出.有谁知道如何实现这一目标?任何帮助都非常感谢!
Positioned(
left: position.dx,
top: position.dy,
child: new Draggable(
data: widget.index,
onDragStarted: widget.setDragging,
onDraggableCanceled: (velocity, offset) {
setState(() {
position = offset;
widget.secondCallback(offset, widget.index);
widget.endDragging();
});
},
child: new GestureDetector(
onTap: () {
widget.callback(widget.caption, widget.index);
},
child: new Text(
widget.caption.caption,
style: new TextStyle(
color: widget.caption.color,
fontSize: widget.caption.fontSize,
),
),
),
feedback: new Material(
type: MaterialType.transparency,
child: new Text(
widget.caption.caption,
style: new TextStyle(
color: widget.caption.color,
fontSize: widget.caption.fontSize),
softWrap: true,
),
),
));
Run Code Online (Sandbox Code Playgroud) 我想要实现的是在固定高度的列中有一个文本小部件。当文本很长时,我希望overflow设置为TextOverflow.ellipsis启动的属性。文本小部件将其maxLines属性设置为高值以允许其自动换行。但是该列中还有其他小部件,无论是在文本小部件之前还是之后。文本小部件位于扩展小部件中,因此它在列中占据尽可能多的空间。完整代码粘贴在下面。
此设置的问题在于文本溢出其容器父级。我在容器上有一个边框装饰,显示了这种情况。为什么会发生这种情况,我该如何解决。
import 'package:flutter/material.dart';
void main() {
runApp(App());
}
class App extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text("Overflow"),
),
body: Center(
child: Container(
width: 200.0,
height: 250.0,
child: Card(
child: Column(children: <Widget>[
Image.asset(
"assets/bereket.jpg",
width: double.infinity,
fit: BoxFit.cover,
),
Expanded(
child: Container(
padding: EdgeInsets.all(8.0),
child: (Column(
children: [
Text(
"???? ????? «???? ?? ???? ???? ???????! ???? ???? ????»",
maxLines: 2,
style: Theme.of(context)
.primaryTextTheme
.subhead …Run Code Online (Sandbox Code Playgroud) 我有一个必须保留在一行上的 TextField(不是文本)小部件。如果输入的文本对于 TextField 框来说太大,我想减小它的字体大小,即如果它溢出则缩小它。我怎样才能做到这一点?
我在有状态的组件中编写了一些这样的代码
if (textLength < 32) {
newAutoTextVM.fontSize = 35.0;
} else if (textLength < 42) {
newAutoTextVM.fontSize = 25.0;
Run Code Online (Sandbox Code Playgroud)
在视图中
fontSize: 25.0,
Run Code Online (Sandbox Code Playgroud)
但它不是很智能,它不能处理调整大小,而且,因为字体大小不是等宽的(快递等),不同的字符占用不同的空间。
我试图在 Flutter 应用程序中省略文本,但我无法设置它。
我设计的视图如下
Positioned(
bottom: 20,
left: 10,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
snapshot.data.results[index].title,
overflow: TextOverflow.ellipsis,
textAlign: TextAlign.start,
style: TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.w600,
color: Colors.white,
),
),
Text(
snapshot.data.results[index].release_date,
style: TextStyle(
fontSize: 18.0,
fontWeight: FontWeight.w400,
color: Colors.white,
letterSpacing: 1.2),
),
],
))
Run Code Online (Sandbox Code Playgroud)