-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Description
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:
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(),
),
);