Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Dart 到达下一个控件时截断文本_Dart_Flutter - Fatal编程技术网

Dart 到达下一个控件时截断文本

Dart 到达下一个控件时截断文本,dart,flutter,Dart,Flutter,考虑以下代码: class MyHomePage extends StatelessWidget { @override Widget build(BuildContext context) { return new Column( children: <Widget>[ new FlatButton( child: new Container( child: new Center(child:

考虑以下代码:

class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new Column(
      children: <Widget>[
        new FlatButton(
          child: new Container(
            child: new Center(child: new Text("ABOVE")),
            height: 300.0,
            color: const Color.fromARGB(255, 255, 0, 0),
          ),
        ),
        new Expanded(
            child: new Text("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",)
        ),
        new FlatButton(
          child: new Container(
            child: new Center(child: new Text("BELOW")),
            height: 300.0,
            color: const Color.fromARGB(255, 255, 0, 0),
          ),
        ),
      ],
    );
  }
}
在我的像素上,这会产生:

我的期望是,文本将继续向上,直到它到达底部按钮,然后剪辑。如果我设置了overflow:TextOverflow.省略号,那么它会在第一行之后截断:

如果我设置maxLines:3,那么它将一直持续到第四行:

然而,我找不到一种方法来继续,直到它到达底部按钮


有人能告诉我吗?

没有直接的样式设置选项可以做到这一点,但是您可以先计算可以在运行时占据可用视图的maxLines,然后只指定overflow和maxLines属性

若要获取可用高度,请使用LayoutBuilder,以提供约束

lineHeight=fontSize*textScaleFactor*lineHeight-scalefactor 最大线=可用高度/线高度

例如:

class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new Material(
      child: new Column(
        children: <Widget>[
          new FlatButton(
            child: new Container(
              child: new Center(child: new Text("ABOVE")),
              height: 300.0,
              color: const Color.fromARGB(255, 255, 0, 0),
            ),
          ),
          new Expanded(child: new LayoutBuilder(builder: (context, constrains) {

            double lineScaleFactor = 1.1; // this is multiplied with fontsize to get lineHeight
            TextStyle style = new TextStyle(fontSize: 16.0,height: lineScaleFactor);
            double scale = 1.0;
            double lineHeight = style.fontSize*scale*lineScaleFactor;

            return new Container(
              child: new Text(
                "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
                overflow: TextOverflow.ellipsis,
                style: style,
                textScaleFactor: scale,
                maxLines: (constrains.maxHeight ~/ lineHeight),
              ),
            );
          })),
          new FlatButton(
            child: new Container(
              child: new Center(child: new Text("BELOW")),
              height: 300.0,
              color: const Color.fromARGB(255, 255, 0, 0),
            ),
          ),
        ],
      ),
    );
  }
}

希望有帮助

你试过maxLines:big_number&overflow:elipsis吗?@Darky是的,它表现出与根本不指定maxLines相同的行为。这确实有帮助,谢谢。我希望这个特定的问题在将来由框架更自然地处理,但我现在把它作为答案。