用输入使行连续变形

时间:2018-06-29 22:29:39

标签: dart flutter

我遇到一种情况,需要在Flutter中用输入内容包装文本。例如:“猫去<TextField>,狗去吠。”

我正在使用Row类以这种方式设置其格式,但是,row类不包装文本。

Widget _buildQuestionText(String sentence) {
 List splitSentence = sentence.split('\$guess');

  return new Container(
    child: Row(
      children: <Widget>[
        new Text(splitSentence[0]),
        new Expanded(child: new TextField()),
        new Text(splitSentence[1]),
      ]
    ),
  );
}

哪个创建:

Text does not wrap

我已经看过使用Flex类,但是无法实现我想要的格式。如何在文本中间输入内容来实现文本换行?

1 个答案:

答案 0 :(得分:0)

Wrap接受要包装的子项列表,而row接受不包装的子项列表。

return new Container(
      child: new Wrap(
        spacing: 8.0, // gap between adjacent chips
        runSpacing: 4.0, // gap between lines
        children: [
          new Text(splitSentence[0]),
          new Container(              
            width: 100.0,
            child: new TextField(                                 
              style: new TextStyle(
                fontSize: 16.0,
                color: Colors.black                  
              )
            )
          ),
          new Text(splitSentence[1]),
        ],
      )
    );