How one can customize the TextFormField
label animation? The InputDecoration
doesn’t provide a way to set a fixed font size or any kind of different animation.
I would like to animate only from the hint location to the label without scaling down the font. Also, if I override the font color property it won’t change when the field is on focus, although this can be easily handled with a FocusNode
listener.
Anyway, does anyone know an easy way to provide my own custom animation or at least, tweak it a bit, without having to recreate a custom form field all from scratch?
Thank you.
Step 1: Locate the file where you have placed the TextField widget. Step 2: Inside the TextField widget, add the decoration parameter and assign the InputDecoration widget. Step 3: Inside the InputDecoration widget, add the labelStyle parameter and assign the TextStyle widget.
In Flutter Slider, you can add labels on the top by following the below steps. Step 1: Add Syncfusion Flutter Sliders package to your dependencies in pubspec. yaml file. Step 2: Initialize the SfSlider widget as a child of any widget.
Just remove the hintText and labelText in InputDecoration . Show activity on this post. The following code removes the LabelText when you write anything in the TextField and shows LabelText when you do not write anything in the TextField. Show activity on this post.
Actually, you can use FocusNode
state to customize floating label font size as well as floating label text color. Depending on the focus state, floating label font size can be forced to look like it's maintaining the same size as hint. Here is a quick example demonstrating this,
class MyApp extends StatefulWidget {
@override
MyAppState createState() => MyAppState();
}
class MyAppState extends State<MyApp> {
FocusNode myFocusNode = new FocusNode();
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Test'),
),
body: Container(
padding: const EdgeInsets.all(20.0),
child: TextFormField(
focusNode: myFocusNode,
decoration: new InputDecoration(
alignLabelWithHint: true,
labelStyle: TextStyle(
fontSize: myFocusNode.hasFocus ? 24 : 18.0,//I believe the size difference here is 6.0 to account padding
color:
myFocusNode.hasFocus ? Colors.blue : Colors.grey),
labelText: 'Hint text',
filled: true,
fillColor: Colors.white,
enabledBorder: new OutlineInputBorder(
borderRadius: new BorderRadius.circular(25.0),
borderSide: new BorderSide(
color: Colors.grey,
),
),
focusedBorder: new OutlineInputBorder(
borderRadius: new BorderRadius.circular(25.0),
borderSide: new BorderSide(
color: Colors.blue,
))),
style: new TextStyle(color: Colors.black),
))));
}
}
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With