代码之家  ›  专栏  ›  技术社区  ›  Mary

有没有办法动态更改颤振文本字段的最大线?

  •  18
  • Mary  · 技术社区  · 7 年前

    我有这样一个文本字段:

    new Flexible(
        fit: FlexFit.loose,
        child: new Container(
            alignment: FractionalOffset.topLeft,
            child: new TextField(
                decoration: new InputDecoration(
                      hintText: 'Add a note',
                ),
                maxLines: 1,
                onChanged: (value) => _showSaveOptions(value),
            ),
        ),
    ),
    

    我想从我的文本字段开始 maxLines 设置为1,但当我键入时,我希望最大行数增加,以便所有文本都保留在页面上,而不必向上滚动。然而,我也不想从 最大线 设置为5或10,因为空的TextField会占用更多必要的空间。我想要实现的行为的一个例子是在谷歌表单中的长答案文本选项中,它以一行开始: enter image description here 并在键入时展开: enter image description here

    我考虑过设置 最大线 对于每次用户点击换行符时递增的计数器,我如何确定用户何时填充了一行?

    2 回复  |  直到 7 年前
        1
  •  55
  •   Hemanth Raj    7 年前

    issue 0.0.16 释放

    new TextField(
        maxLines: null,
        keyboardType: TextInputType.multiline,
    ) 
    

        2
  •  4
  •   AH Rasel    5 年前

    它看起来像一个文本区域。你可以试试 最大线

    最大线:8

    TextField(
            maxLines: 8,
            decoration: InputDecoration(hintText: "Enter your text here", border: OutlineInputBorder(),
            labelText: 'Post Body'),
        ),