Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to move TextField's labelText and icon to the right side

Tags:

flutter

dart

I want to move the icon and the label text to the right side of the Text Field. I tried textAlign: TextAlign.right but it's only for input text.

enter image description here

    TextFormField(
      textAlign: TextAlign.right,
      textDirection: TextDirection.rtl,
      keyboardType: TextInputType.multiline,
      maxLines: 2,
      decoration: const InputDecoration(
        icon: Icon(Icons.description),  
        labelText: 'details',
      ),
  ),
like image 386
SUX Avatar asked Oct 29 '25 02:10

SUX


1 Answers

Use suffixIcon, An icon that appears after the editable part of the text field and after the suffix or suffixText, within the decoration's container.Official API Doc

TextFormField(
    textAlign: TextAlign.right,
    decoration: InputDecoration(
       hintText: "Enter a message",
       suffixIcon: Icon(Icons.description),
    ),
),

This exactly what you need, you need to customize some style

@override
  Widget build(BuildContext context) {
    return Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Container(
              width: 200,
              child: TextFormField(
                textAlign: TextAlign.right,
                decoration: InputDecoration(
                  hintText: "Enter a message",
                ),
              ),
            ),
            Container(
              child: Icon(Icons.description),
            ),
          ],
    );
  }

Demo

like image 143
Robin Avatar answered Oct 31 '25 17:10

Robin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!