Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can you add a fixed placeholder text in a Flutter textfield

Im looking for a way to show an example of a text input expected in a TextFormField in Flutter, the idea would be similar to using a hintText, but this hint not disappearing and adapting to the users input, i do not need formatting or anything.

I tried putting one textFormField stacked on another but this hacky way creates new issues that i cannot resolve.

The exprected result would be similar to the following image:

Expected Result

Code Snippet:

Stack(
      children: [
        TextFormField(
          scrollController: scrollController,
          focusNode: focusNode,
          controller: textController,
          keyboardType: widget.textInputType,
          decoration: InputDecoration(
            hintTextDirection: TextDirection.ltr,
            labelText: "label",
            hintText: "Hint",
            fillColor: white,
          ),
        ),
        if (IsTextFormSelected)
          TextFormField(
            scrollController: secondScrollController,
            focusNode: secondFocusNode,
            controller: secondController,
            textCapitalization: TextCapitalization.sentences,
            decoration: InputDecoration(
              border: InputBorder.none,
              focusedBorder: InputBorder.none,
              enabledBorder: InputBorder.none,
              errorBorder: InputBorder.none,
              disabledBorder: InputBorder.none,
              hintTextDirection: TextDirection.ltr,
              fillColor: Colors.transparent,
            ),
            onTap: () {
              // RequestsFocus from mainTextFormField onTap
              focusNode.requestFocus();
            },
          ),
      ],
    );

I would really appreciate any ideas.

like image 842
Shistastic Avatar asked Oct 28 '25 13:10

Shistastic


1 Answers

Try below code using Single TextField:

TextFormField(
      textCapitalization: TextCapitalization.sentences,
      decoration: InputDecoration(
        labelText: "label",
        hintText: "Hint",
        border: InputBorder.none,
        focusedBorder: InputBorder.none,
        enabledBorder: InputBorder.none,
        errorBorder: InputBorder.none,
        disabledBorder: InputBorder.none,
        hintTextDirection: TextDirection.ltr,
        fillColor: Colors.transparent,
      ),
    ),

Result-> image

Result-> image

like image 199
Ravindra S. Patil Avatar answered Oct 31 '25 11:10

Ravindra S. Patil



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!