3

I want the Hint Text to remain even when Text is entered in the TextField: I want to do the same

But if I give TextField something like "hintText:" in simple way, Hint Text disappears when TextField is entered: Current status.

What should I do so that the hintText doesn't disappear even when a value is entered in the TextField?

. . . I tried the following:

I. I tried using the suffix widget. But it appears from the end of the TextField. (If it was possible to make the suffix widget appear after the text, I think the problem would have been solved.) : Ignore the malfunction

II. Obviously Prefix Widget can't help here : with Prefix Widget

Any answers are welcome, thanks.

1 Answers1

0

You can use label to be visible at the top of the TextField & the hint u can simply add below line:

floatingLabelBehavior: FloatingLabelBehavior.always

full example is given below

TextFormField(
  controller: textController,
  style: theme.textTheme.bodyText2,
  keyboardType: keyboardType ?? TextInputType.number,
  enableInteractiveSelection: false,
  decoration: InputDecoration(
      labelText: labelText,
      labelStyle: theme.textTheme.headline6,
      suffixText: suffixText ?? '',
      border: OutlineInputBorder(
        borderSide:
            BorderSide(color: theme.textTheme.bodyText2.color, width: 2),
      ),
      hintText: '0.0',
      floatingLabelBehavior: FloatingLabelBehavior.always),
  validator: (value) {
    if (value.isEmpty) {
      return 'Please enter some text';
    }
    return null;
  },
  onChanged: (String text) => onChange(text),
);
Babul
  • 1,076
  • 7
  • 9
  • Thanks for the answer, but you seem to have misunderstood the question: The HintText should not disappear even after entering a value in the TextField. Like this: https://i.stack.imgur.com/wvwAK.gif – Хуршид Собиров Jul 26 '22 at 06:54