I have label in the top left corner of my TextField. I want the user to be able to see the hint always (and after that he filled the form), but it disappears when I tap.
@override
Widget build(BuildContext context) {
return TextField(
decoration: InputDecoration(
floatingLabelBehavior: FloatingLabelBehavior.never,
label: Align(
alignment: Alignment.topLeft,
child: Text(
_text,
textAlign: TextAlign.left,
style: const TextStyle(fontSize: 15),
)),
focusedBorder: const OutlineInputBorder(
borderSide: BorderSide(color: Colors.black),
borderRadius: BorderRadius.all(Radius.circular(10))),
enabledBorder: const OutlineInputBorder(
borderSide: BorderSide(color: Colors.black),
borderRadius: BorderRadius.all(Radius.circular(10)),
)));
}
2
Answers
The material design suggest to use the
labelText
property on theInputDecoration
. Maybe you have already tried and dismissed it.. but I’m checking just in case… have you tried that?This will be the typical outcome:
If you do not want to go with hintText, you can make a stack where the first child is the ’TextField’ and the other is
Positioned
for your text.