import 'package:flutter/material.dart';
 
 class TextFiledMessageSend extends StatelessWidget {
 const TextFiledMessageSend({super.key});
 
   @override
 Widget build(BuildContext context) {
 return TextField(
      textAlignVertical: TextAlignVertical.center,
      decoration: InputDecoration(
        border: InputBorder.none,
        hintText: "Type your message ",
        // contentPadding: const EdgeInsets.symmetric(horizontal: 10),
        prefixIcon: IconButton(
            onPressed: () {}, icon: const Icon(Icons.emoji_emotions, size: 22)),
      ),
    );
}

I want that the hint Text and the cursor is in the center horizontal as wel as the prefixIcon,suffixIcon is in the center :

Here is the image of the widget

2

There are 2 best solutions below

0
Grubz On BEST ANSWER

You can do it by removing the size of the prefixIcon and applying a contentPadding :

TextField(
  decoration: InputDecoration(
    border: InputBorder.none,
    hintText: 'Type your message',
    contentPadding: EdgeInsets.symmetric(horizontal: 20, vertical: 15),
    prefixIcon: IconButton(
          onPressed: () {},
          icon: const Icon(Icons.emoji_emotions)),
  ),
);
2
MendelG On

The TextField is expanding.

So, set isDense to true on the InputDecoration and remove textAlignVertical: TextAlignVertical.center:

TextField(
        // textAlignVertical: TextAlignVertical.center,<-- Remove this
        decoration: InputDecoration(
          isDense: true, // <-- Added this
          border: InputBorder.none,
          hintText: "Type your message ",
          // contentPadding: const EdgeInsets.symmetric(horizontal: 10),
          prefixIcon: IconButton(
              onPressed: () {},
              icon: const Icon(Icons.emoji_emotions, size: 22)),
        ),
      )