skip to Main Content

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.

My code

  @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


  1. The material design suggest to use the labelText property on the InputDecoration. 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:

    enter image description here

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search