Flutter – two text in a row with left one overflowing gracefully

前端 未结 2 1557
余生分开走
余生分开走 2021-02-14 10:15

How do I get two side-by-side Text widgets to only allow the left-most one to overflow gracefully?

One text widget in a column is easy to overflow gracefully. Two text wi

2条回答
  •  有刺的猬
    2021-02-14 10:36

    You can use the Flexible widget:

    Widget _listItemSubtitle(String subtitle) {
      return new Flexible(
        fit: FlexFit.loose,
        child: Text(
          "[$subtitle]",
          softWrap: false,
          overflow: TextOverflow.fade,
        ),
      );
    }
    


    Alternative:

    If you prefer that the time widget is always on the right, you could wrap the subtitle text in an Expanded widget:

    Widget _listItemSubtitle(String subtitle){
      return Expanded(
        child: Text(
          "[$subtitle]",
          softWrap: false,
          overflow: TextOverflow.fade,
        ),
      );
    }
    

提交回复
热议问题