Это происходит из-за высоты, которую вы даете родительскому контейнеру. Может быть два способа выровнять текст подсказки по вертикали (они не зависят друг от друга, выберите один)
child: Container(
// height: 48, //ONE - Remove the static height
child: TextField(
textAlignVertical: TextAlignVertical.center,
style: TextStyle(
textBaseline: TextBaseline.alphabetic,
color: Colors.red,
),
onChanged: (value) {},
decoration: InputDecoration(
// contentPadding: EdgeInsets.all(8.0), //TWO - Specify the padding if you want your custom height.
filled: true,
alignLabelWithHint: true,
hintText: "Buscar por código",
hintStyle: TextStyle(color: Colors.red),
prefixIcon: Icon(Icons.search, color: Colors.red),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(40)),
borderSide: BorderSide(color: Colors.red, width: 1.0),
),
),
),
),
- Удалить высоту контейнера
- Если вы хотите размер родительского контейнера по вашему желанию, вы должны указать некоторые внутренние отступы для содержимого.
Изменить: вы потеряете границу, когда нажмете на TextField, поскольку вы ничего не передаете свойство focusedBorder
для TextField
. Следуйте приведенному ниже коду:
decoration: InputDecoration(
filled: true,
alignLabelWithHint: true,
hintText: "Buscar por código",
hintStyle: TextStyle(color: Colors.red),
prefixIcon: Icon(Icons.search, color: Colors.red),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(40)),
borderSide: BorderSide(color: Colors.red, width: 1.0),
),
focusedBorder: OutlineInputBorder( //Add this to your code...
borderRadius: BorderRadius.all(Radius.circular(40)),
borderSide: BorderSide(color: Colors.red, width: 1.0),
),
),