Skip to content

Add support for using widget for hint text inside Text field. #161130

@saninthottungal

Description

@saninthottungal

Use case

Not able to assign a Widget to hint text, as hint parameter in InputDecoration class is only accepting String value.

The Problem:

I want to achieve a Slide Transition between hint texts like shown in the attachment below:

InShot_20250104_231904812

for animating between texts, i have a found a nice package: animated text kit, but the API exposes a widget for animating between texts. so i am not able to use it directly on hint text, because hint text property inside InputDecoration is only accepting a value of String. here is the code snippet:

TextField(
      decoration: InputDecoration(
        hintText: AnimatedTextKit(  // ERROR
          animatedTexts: [ ... ],
        ),
      ),
    );

What i have tried:

tried using label property instead of hint text, but the behavior of label is different. hint text only disappears when user starts typing. but label disappearing on Text Field getting focused itself. I want the behavior of hint text, so that when Text Field is focused, the hint texts transitions won't disappear, here is the snippet when label is used:

TextField(
      decoration: InputDecoration(
        label: AnimatedTextKit( // NO ERROR
          animatedTexts: [ ... ],
        ),
        floatingLabelBehavior: FloatingLabelBehavior.never,
      ),
    );

work around i used:

i stacked the Widget from package on top of Text field, this is working but now i have to keep logic for this separately for showing and hiding the hint texts i added. Here is demo snippet(not the exact code i used):

Stack(
      children: [
        TextField(),
        Positioned(
          top: 30,
          left: 50,
          child: AnimatedTextKit(
            animatedTexts: [],
          ),
        ),
      ],
    );

Proposal:

just like how label and labelText is available, A hint property that accepts a Widget inside InputDecoration class, like this:

TextField(
      decoration: InputDecoration(
        hint: AnyWidget(),
      ),
    );

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: text inputEntering text in a text field or keyboard related problemsc: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutterf: material designflutter/packages/flutter/material repository.frameworkflutter/packages/flutter repository. See also f: labels.good first issueRelatively approachable for first-time contributorsr: fixedIssue is closed as already fixed in a newer versionteam-text-inputOwned by Text Input teamtriaged-text-inputTriaged by Text Input teamworkaround availableThere is a workaround available to overcome the issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions