简体   繁体   English

如何更改textformfield中文字的position?

[英]How to change the position of the text in the textformfield?

This is the design I want:这是我想要的设计: 在此处输入图像描述

This is my current design:这是我目前的设计: 在此处输入图像描述

I am new to using flutter.我是使用 flutter 的新手。 I want to ask for an opinion on how to make text in the textformfield at what position according to the design I want.我想就如何根据我想要的设计在 position 的 textformfield 中制作文本征求意见。 I try to use contentPadding: EdgeInsets.symmetric(vertical: 40), and height in textformfield style but still can't solve my problem.我尝试使用 contentPadding: EdgeInsets.symmetric(vertical: 40) 和 textformfield 样式的高度,但仍然无法解决我的问题。 Please advise from stack overflow.请注意堆栈溢出。

This is my code:这是我的代码:

Container(
                          width: double.infinity,
                          margin: EdgeInsets.fromLTRB(10, 0, 10, 10),
                          padding: EdgeInsets.all(15),
                          decoration: BoxDecoration(
                            border: Border.all(
                              color: Colors.transparent,
                              width: 1.0,
                            ),
                          ),
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              SizedBox(
                                height: 30,
                                child: Text(
                                  'Important patient note',
                                  style: TextStyle(
                                      fontWeight: FontWeight.bold,
                                      fontSize: 16),
                                ),
                              ),
                              SizedBox(
                                width: 950,
                                child: TextFormField(
                                  textAlign: TextAlign.start,
                                  style: const TextStyle(color: Colors.black),
                                  controller: importantNotes,
                                  onSaved: (String? value) {
                                    importantNotes.text = value!;
                                  },
                                  decoration: const InputDecoration(
                                    contentPadding: EdgeInsets.all(70.0),
                                    border: OutlineInputBorder(),
                                    hintText: 'Important patient note',
                                    hintStyle: TextStyle(
                                        color: Colors.black, fontSize: 16,),
                                  ),
                                ),
                              )
                            ],
                          ))

try this one试试这个

 Widget textfield(
      String hint, TextEditingController _controller, bool obsecurtext) {
    return Container(
      width: MediaQuery.of(context).size.width - 70,
      height: 60,
      child: TextFormField(
        obscureText: obsecurtext,
        controller: _controller,
        decoration: InputDecoration(
          labelStyle: TextStyle(fontSize: 15),
          focusedBorder: OutlineInputBorder(
            borderRadius: BorderRadius.circular(21),
            borderSide:
            BorderSide(width: 1, color: Color.fromARGB(255, 226, 135, 230)),
          ),
          enabledBorder: OutlineInputBorder(
            borderRadius: BorderRadius.circular(21),
            borderSide:
            BorderSide(width: 1, color: Color.fromARGB(255, 231, 127, 127)),
          ),
          hintText: hint,
        ),
      ),
    );
  }

usage textfield("Email", _email, false)使用textfield("Email", _email, false)

Just remove contentPadding: EdgeInsets.all(70.0),只需删除contentPadding: EdgeInsets.all(70.0),

SizedBox(
    width: 950,
    child: TextFormField(
      textAlign: TextAlign.start,
      maxLines : 5, // add this
      style: const TextStyle(color: Colors.black),
      controller: importantNotes,
      onSaved: (String? value) {
        importantNotes.text = value!;
      },
      decoration: const InputDecoration(
        contentPadding: EdgeInsets.all(70.0), // remove or set it to 0
        border: OutlineInputBorder(),
        hintText: 'Important patient note',
        hintStyle: TextStyle(
            color: Colors.black, fontSize: 16,),
      ),
    )),

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM