我有一个Text小部件,如果它超过一定的大小,可以截断:
ConstrainedBox(
constraints: BoxConstraints(maxHeight: 50.0),
child: Text(
widget.review,
overflow: TextOverflow.ellipsis,
)
);
Run Code Online (Sandbox Code Playgroud)
或最大行数:
RichText(
maxLines: 2,
overflow: TextOverflow.ellipsis,
text: TextSpan(
style: TextStyle(color: Colors.black),
text: widget.review,
));
Run Code Online (Sandbox Code Playgroud)
我的目标是只有在溢出完成后才能扩展文本.有没有正确的方法来检查文本是否溢出?
我发现在RichText中有一个RenderParagraph renderObject,它有一个私有属性TextPainter _textPainter,有一个bool didExceedMaxLines.
简而言之,我只需要访问,richText.renderObject._textPainter.didExceedMaxLines但正如您所看到的,它是使用下划线私有的.
我正在努力使用其GlobalKey来获取Widget的高度。呈现Layout之后,将调用获取高度的函数,以确保上下文可用,但是key.currentState和key.currentContext仍返回null。
import 'package:flutter/material.dart';
class TestPage extends StatefulWidget{
@override
State<StatefulWidget> createState() => new TestPageState();
}
class TestPageState extends State<TestPage>{
final TestWidget testWidget = new TestWidget();
@override
initState() {
//calling the getHeight Function after the Layout is Rendered
WidgetsBinding.instance
.addPostFrameCallback((_) => getHeight());
super.initState();
}
void getHeight(){
final GlobalKey key = testWidget.key;
//returns null:
final State state = key.currentState;
//returns null:
final BuildContext context = key.currentContext;
//Error: The getter 'context' was called on null.
final RenderBox box = state.context.findRenderObject();
print(box.size.height);
print(context.size.height);
}
@override …Run Code Online (Sandbox Code Playgroud) 在ListView中创建图像时出现错误“ 底部溢出199像素 ”,在我用Google搜索之后,所有这些都建议我添加:
resizeToAvoidBottomPadding: false
Run Code Online (Sandbox Code Playgroud)
但是,它不起作用!错误仍然存在。
SafeArea小部件也无法解决问题。这是我的布局的简短代码版本:
body: ListView(
children:<Widget> [
new Container(
child: new Stack(
children:<Widget> [
//THE WIDGET
new Container(), //THE BACKGROND IMAGE
new Positioned(
child: Column(
children:<Widget>[
new Transform(),
new FadeTransition(),
new FadeTransition(),
Divider(),
new Row(),
//THE IMAGE THAT I WANT TO ADD
new Container(
height: 360.0
decoration: BoxDecoration(
image: DecorationImage(
image: Assetimage('lake.jpg)
Run Code Online (Sandbox Code Playgroud)