Flutter - How to show text and icon in one line in row?

荒凉一梦 提交于 2020-06-27 18:36:08

问题


I am using row widget with three child widgets: Text Icon Text

I want all of them to appear in single line same level horizontally and drop to new line if text increases.

I am using below code for Row widget but last Text widget is not aligned correctly

The text dropping should start below the "Tap" and "on the right hand" is not aligned

Row(
  mainAxisAlignment: MainAxisAlignment.start,
  mainAxisSize: MainAxisSize.min,
  children: <Widget>[
    Text(
      'Tap ',
      style: TextStyle(
        fontSize: 17,
      ),
    ),
    Icon(Icons.add),
    Expanded(
      child: Text(
        'on the right hand corner to start a new chat.',
        style: TextStyle(
          fontSize: 17,
        ),
      ),
    )
  ],
)

回答1:


Use Text.rich with WidgetSpan to put icon inside text (inline)

Text.rich(
  TextSpan(
    style: TextStyle(
      fontSize: 17,
    ),
    children: [
      TextSpan(
        text: 'Tap',
      ),
      WidgetSpan(
        child: Icon(Icons.add),
      ),
      TextSpan(
        text: 'on the right hand corner to start a new chat.',
      )
    ],
  ),
)


来源:https://stackoverflow.com/questions/61899181/flutter-how-to-show-text-and-icon-in-one-line-in-row

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!