Search code examples
flutter

set min height of textfiled in flutter


I have a textfiled in container, and i want the textfiled support multiline, so i can not the the height of the container. but how to set the default height of the textfield when there is no word? enter image description here enter image description here I have try the contentPadding, but not work. here is my code:

TextField(
                              controller: _textEditingController,
                              decoration: InputDecoration(
                                hintText: "留下你的评论吧~",
                                contentPadding: EdgeInsets.only(left: getMyWidth(10), right: getMyWidth(10)),
                                fillColor: default_bg,
                                filled: true,
                                border: OutlineInputBorder(borderSide: BorderSide.none, borderRadius: BorderRadius.all(Radius.circular(getMyWidth(5)))),
                              ),
                              style: makeBlackStyle(),
                              keyboardType: TextInputType.multiline,
                              maxLines: null,
                              cursorColor: themeColor,
                              onChanged: (str) {
                                setState(() {
                                  inputStr = str;
                                });
                              },
                            )

so, my question is: How to set the default height of the textfield when there is no word? I want to decrease the default height of the textfiled , and need support mulitiline


Solution

  • Replace your code with following to have at-least 3 lines in your TextField:

    TextField(
      minLines: 3,
      controller: _textEditingController,
      decoration: InputDecoration(
        hintText: "留下你的评论吧~",
        contentPadding: EdgeInsets.only(left: getMyWidth(10), right: getMyWidth(10)),
        fillColor: default_bg,
        filled: true,
        border: OutlineInputBorder(borderSide: BorderSide.none, borderRadius: BorderRadius.all(Radius.circular(getMyWidth(5)))),
      ),
      style: makeBlackStyle(),
      keyboardType: TextInputType.multiline,
      maxLines: null,
      cursorColor: themeColor,
      onChanged: (str) {
        setState(() {
          inputStr = str;
        });
      },
    )