Reputation: 900
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.
TextFormField(
textAlign: TextAlign.right,
textDirection: TextDirection.rtl,
keyboardType: TextInputType.multiline,
maxLines: 2,
decoration: const InputDecoration(
icon: Icon(Icons.description),
labelText: 'details',
),
),
Upvotes: 4
Views: 10644
Reputation: 1
you have to use of suffixIcon suffixIcon: Icon( Ionicons.ios_search, color: Colors.black, ),
Upvotes: 0
Reputation: 900
i just found Directionality widget and it changes the direction for everything include label and icon
Directionality(
textDirection: TextDirection.rtl,
child: TextFormField(
textAlign: TextAlign.right,
textDirection: TextDirection.rtl,
keyboardType: TextInputType.multiline,
maxLines: 2,
decoration: const InputDecoration(
icon: Icon(Icons.description),
labelText: 'details',),
),
)
Upvotes: 3
Reputation: 5427
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),
),
],
);
}
Upvotes: 6
Reputation: 2154
Create a variable
var _controller = TextEditingController();
And your TextField
:
TextField(
controller: _controller,
decoration: InputDecoration(
hintText: "Enter a message",
suffixIcon: IconButton(
onPressed: (){},
icon: Icon(Icons.phone),
),
),
)
Upvotes: 2