flutterdarttextfield

When I set the textfield to the next line in Flutter, the text goes up


I want to get rid of the letters going up when I hit enter in a text field. What should I do?

It's part of the code.

Container(
                          child: TextField(
                            textAlign: TextAlign.center,
                            autofocus: true,
                            // controller: myController,
                            onChanged: (value) {
                              // print('$value');
                              setState(() {
                                mainText = value;
                              });
                            },
                            keyboardType: TextInputType.multiline,
                            minLines: 1,
                            maxLines: 10,
                            decoration: InputDecoration(
                              focusedBorder: InputBorder.none,
                              enabledBorder: InputBorder.none,
                              hintText: "짧은 글귀를 집필해주세요",
                              hintStyle:
                                  TextStyle(fontSize: 14, color: Colors.black),
                            ),
                          ),
                        )

Solution

  • As per your hint text you just want short text and you can achieve by integrating with only single line textfield

      Container(
          child: TextField(
            textAlign: TextAlign.center,
            autofocus: true,
            // controller: myController,
            onChanged: (value) {
              setState(() {
                mainText = value;
              });
            },
            keyboardType: TextInputType.text, // this is change
            textInputAction: TextInputAction.done, // this is change
            decoration: InputDecoration(
              focusedBorder: InputBorder.none,
              enabledBorder: InputBorder.none,
              hintText: "짧은 글귀를 집필해주세요",
              hintStyle: TextStyle(fontSize: 14, color: Colors.black),
            ),
          ),
        )
    

    for multiline text:

    keyboardType: TextInputType.multiline,
    maxLines: 5,
    textInputAction: TextInputAction.newline,