how to use Text Widget with autosize in a AspectRatio Widget

时间:2018-06-04 17:24:30

标签: gridview flutter

I have a layout which I want to size by an AspectRatio, and where a Text Widget should fill the remaining place in one corner. It should show some lines of Text and then the ellipsis.

But it does not work: The Row containing the Text grows so much that the Text can show all the content. I can limit the Text widget by defining maxLines - but exactly this should be done by some Layout Widget, I hope!

This is my Widget, simplified:

Container(
    child:GestureDetector(
        onTap: () => rssOnTap(index),
        child: AspectRatio(
            aspectRatio: 3.0,
            child: Row(
                crossAxisAlignment: CrossAxisAlignment.start,
                mainAxisSize: MainAxisSize.min,
                children: <Widget>[
                    Expanded(flex:2,
                        child: Image.network(_url)),
                    Expanded(flex:3,
                        child: Text(_summary),
                              maxLines: 5,
                              softWrap: true,
                              overflow: TextOverflow.ellipsis,
                          )
                    )
                ],
            )
        )
    )
);

(It compiles; if not, I mistaked on the simplyfiyng here, sorry!)

When I don't use overflow:, I just get one line. If I use overflow:, I get the complete _summary. Only if I use overflow: and maxLines:, I get a shorter widget.

But how do I fill the Text(_summary) only the leftover space in a AspectRatio widget? Maybe one more detail:

The Widget is used in a GridView.builder with a SliverGridDelegateWithMaxCrossAxisExtent.

Added two screenshots:

the <code>Text</code> widget overflows. It should be stripped.

This is the not simplified version of the layout with too high <code>Texts</code>

0 个答案:

没有答案