标签文本在TextField中不会居中吗?

时间:2020-10-22 20:46:21

标签: flutter dart

我试图将我的labelText居中在TextField中,但是我无法终生使它居中。有人看到一个明显的问题会导致此吗?谢谢!

                      Container(
                        width:
                        MediaQuery.of(context).size.width * .85,
                        height:
                        MediaQuery.of(context).size.height * .12,
                        decoration: BoxDecoration(
                            color: Colors.white,
                            border: Border.all(color: Colors.white),
                            borderRadius: BorderRadius.all(
                                Radius.circular(12))),
                        child: TextField(
                          textAlign: TextAlign.center,
                          controller: _notesEditingController,
                          obscureText: false,
                          decoration: InputDecoration(
                              contentPadding: EdgeInsets.symmetric(vertical: 40.0),
                              fillColor: Colors.white,
                              border: OutlineInputBorder(
                                borderRadius: BorderRadius.all(
                                    Radius.circular(12.0)),
                              ),
                              labelText: 'notes',
                              labelStyle: TextStyle(
                                color: Color.fromRGBO(105, 105, 105, 10),
                              )),
                        ),
                      ),

1 个答案:

答案 0 :(得分:1)

请尝试此操作,替换labelText并使用hintText

Container(
   child: TextField(
     textAlign: TextAlign.center,
     decoration: InputDecoration(
       hintText: 'Center the text',
     ),
   ),
)