Flutter "Hint Text" Animation - flutter

i would like to animtate "Hint text" in "InputDecoration". I found "Animated_text_kit" which alove to animate text, but i don't know how to implement this in inputDecoration - Hint text
Here is my InputDecoration Code:
decoration: InputDecoration(
enabledBorder: inputBorderDecoration,
alignLabelWithHint: true,
focusedBorder: focusedBorder,
suffixIcon: isWriting
? null
: IconButton(
icon: Image.asset('assets/images/microphone.png'),
color: Colors.black,
onPressed: () {
print('microphone taped');
}),
hintText: "Message...",
hintStyle: TextStyle(color: AppColor.darkGrey, fontSize: 18),
border: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.red.withOpacity(0.2),
),
borderRadius: BorderRadius.circular(15),
),
contentPadding:
EdgeInsets.symmetric(horizontal: 10, vertical: 0),
filled: true,
fillColor: Colors.white.withOpacity(0.3),
),

Related

how do i reduce the top and bottom padding of flutter textfield within the border?

how do i reduce the top and bottom padding of flutter textfield within the border? there is too much space for top and bottom.
TextField(
textInputAction: TextInputAction.search,
controller: controller,
focusNode: focusNode,
autofocus: true,
cursorColor: Theme.of(context).primaryColor,
onChanged: (text) {
text.length >= 4
? provider.fetchSearchName(text)
: buildNoData();
},
decoration: InputDecoration(
suffixIcon: IconButton(
onPressed: clearText,
color: Theme.of(context).primaryColor,
icon: Icon(Icons.cancel_outlined)
),
labelText: 'Search',
labelStyle: TextStyle(color: Colors.white),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(width: 2, color: Theme.of(context).primaryColor),
// borderRadius: BorderRadius.circular(10),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(width: 2, color: Theme.of(context).primaryColor),
// borderRadius: BorderRadius.circular(10),
)
),
),
You may use contentPadding: within InputDecoration widget.
Here's the Code
TextField(
textInputAction: TextInputAction.search,
controller: controller,
focusNode: focusNode,
autofocus: true,
cursorColor: Theme.of(context).primaryColor,
onChanged: (text) {
text.length >= 4
? provider.fetchSearchName(text)
: buildNoData();
},
decoration: InputDecoration(
contentPadding: EdgeInsets.symmetric(vertical: 5, horizontal: 12),
suffixIcon: IconButton(
onPressed: clearText,
color: Theme.of(context).primaryColor,
icon: Icon(Icons.cancel_outlined)
),
labelText: 'Search',
labelStyle: TextStyle(color: Colors.white),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(width: 2, color: Theme.of(context).primaryColor),
// borderRadius: BorderRadius.circular(10),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(width: 2, color: Theme.of(context).primaryColor),
// borderRadius: BorderRadius.circular(10),
)
),
),

label text is displaying at wrong place when typing

As the image is shown below, the first image displays my text field before I click on it. the second image displays how it displays when after start typing and clicking on it. I want to remove that label text display while typing. how can I do that?
TextFormField(
controller: usernameEditingController,
decoration: InputDecoration(
fillColor: textWhite,
filled: true,
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(20.0),
borderSide: const BorderSide(
color: textdarkBlue,
),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(20.0),
borderSide: const BorderSide(
color: textdarkBlue,
),
),
errorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(20.0),
borderSide: const BorderSide(color: Colors.red),
),
focusedErrorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(20.0),
borderSide: const BorderSide(color: Colors.red),
),
isDense: true,
contentPadding: EdgeInsets.fromLTRB(10, 30, 10, 0),
labelText: "User Name",
labelStyle: TextStyle(
fontSize: 15,
color: textdarkBlue,
),
hintText: "ex: James",
hintStyle: TextStyle(
color: textdarkBlue,
fontFamily: "Paralucent",
fontSize: 14)),
style: TextStyle(
color: textdarkBlue,
),
validator: (text) {
if (text!.isEmpty) {
return "Username can't be empty";
} else {
return null;
}
},
onChanged: (String? text) {
userName = text!;
//print(userName);
},
),
It is displaying as OutlineInputBorder's behavior.
There are few different ways, One is using FocusNode, goal is to provide labelText:null on focus change.
String userName = "";
late FocusNode focusNode = FocusNode()
..addListener(() {
setState(() {});
});
.....
TextFormField(
// controller: usernameEditingController,
focusNode: focusNode,
decoration: InputDecoration(
labelText: focusNode.hasFocus ? null : "User Name",
That is the behaviour of labelText property if you don't want it , simply remove it and use hintText instead
TextFormField(
controller: usernameEditingController,
decoration: InputDecoration(
fillColor: textWhite,
filled: true,
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(20.0),
borderSide: const BorderSide(
color: textdarkBlue,
),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(20.0),
borderSide: const BorderSide(
color: textdarkBlue,
),
),
errorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(20.0),
borderSide: const BorderSide(color: Colors.red),
),
focusedErrorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(20.0),
borderSide: const BorderSide(color: Colors.red),
),
isDense: true,
contentPadding: EdgeInsets.fromLTRB(10, 30, 10, 0),
hintText: "ex: James",
hintStyle: TextStyle(
color: textdarkBlue,
fontFamily: "Paralucent",
fontSize: 14)),
style: TextStyle(
color: textdarkBlue,
),
validator: (text) {
if (text!.isEmpty) {
return "Username can't be empty";
} else {
return null;
}
},
onChanged: (String? text) {
userName = text!;
//print(userName);
},
),

How to change the inside color of a Textfield in flutter?

I want to change the Color of an textfield in flutter.
Means the area within the InputBorder.
I tried to wrap the textfield in container, and change the color of the container, but this seems a fool's step to solve the problem.
I tried the fillColor option, but nothing changed.
Here is my Code -->
Container(
padding: EdgeInsets.fromLTRB(
10,
screenHeight * 0.016415869,
10,
0,
),
height: screenHeight * 0.082079343,
child: TextField(
cursorColor: Color(0xFF7675E0),
textAlign: TextAlign.left,
decoration: InputDecoration(
fillColor: Colors.black, //Nothing Worked
contentPadding: EdgeInsets.fromLTRB(
15,
screenHeight * 0.002735978,
2,
screenHeight * 0.002735978,
),
hintText: "Search",
hintStyle: GoogleFonts.sniglet(
fontSize: screenHeight * 0.020519836,
color: Color(0xFFC6C8CA),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(5.0),
borderSide: BorderSide(
color: Colors.grey[200].withOpacity(0.2),
),
),
prefixIcon: Icon(Icons.search),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.grey[200].withOpacity(1),
),
),
),
),
),
Thanks in Advance :)
Try out this:-
decoration: InputDecoration(
filled: true,
fillColor: Colors.grey,
If you want to set the color to your text field then there is one boolean variable which you need to set true so your color will be added to your text field
Container(
child: TextField(
cursorColor: Color(0xFF7675E0),
textAlign: TextAlign.left,
decoration: InputDecoration(
fillColor: Colors.black, // you can change color of textfield
filled: true, // this should be true if you want to set color to textfield
hintText: "Search",
prefixIcon: Icon(Icons.search),
),
),
),
Basically you can leave your code as you provided us. The important missing value is
filled: true
With this value applied you can style the background color easy.
Reference to the doc: https://api.flutter.dev/flutter/material/TextField-class.html
don't use Container for TextField decoration, there are more property into TextField
TextField use
decoration: InputDecoration(
filled: true,
fillColor: Colors.white10,
border: new OutlineInputBorder(
borderRadius: new BorderRadius.all(
new Radius.circular(14.0),
),
),
TextField(
controller: usernameController,
keyboardType: TextInputType.emailAddress,
style: TextStyle(color: Colors.white),
decoration: InputDecoration(
filled: true,
fillColor: Colors.white10,
border: new OutlineInputBorder(
borderRadius: new BorderRadius.all(
new Radius.circular(14.0),
),
),
hintText: 'Username',
hintStyle: TextStyle(color: Colors.white),
contentPadding: const EdgeInsets.all(24),
prefixIcon: Icon(Icons.person, color: Colors.white),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.white10),
borderRadius: BorderRadius.circular(14),
),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.white10),
borderRadius: BorderRadius.circular(14),
),
),
),

Flutter wrong position of text in textfield after changing height

According to my design I have a TextField with 30pt of height.
Here's how I am trying to do that:
Container(
height: 30,
child: new TextField(
textAlign: TextAlign.start,
decoration: new InputDecoration(
prefixIcon: Icon(Icons.search),
border: new OutlineInputBorder(
borderRadius: const BorderRadius.all(
const Radius.circular(30.0),
),
),
filled: true,
hintStyle: new TextStyle(color: Colors.grey[800]),
hintText: "Search",
fillColor: Colors.lightGreen),
)),
And here's the result:
How can I align hint and text vertically?
Set contentPadding to EdgeInsets.symmetric(horizontal: 0) in InputDecoration. This will remove the default horizontal padding for the Text:
Container(
height: 35,
child: TextField(
decoration: InputDecoration(
contentPadding: EdgeInsets.symmetric(horizontal: 0),
prefixIcon: Icon(Icons.search),
border: OutlineInputBorder(
borderRadius: const BorderRadius.all(
const Radius.circular(5.0),
),
),
filled: true,
hintStyle: TextStyle(color: Colors.grey[800]),
hintText: "Search",
fillColor: Colors.lightGreen),
),
),

Flutter textfield background color on focus

I have a rounded textfield. It works well, but when the user taps on it, a grey color background appears. How can I disable that splash effect?
This is my code and result:
new Container(
margin: const EdgeInsets.only(left: 30.0, top: 60.0, right:
30.0),
height: 40.0,
decoration: new BoxDecoration(
color: Colors.white,
borderRadius: new BorderRadius.all(new Radius.circular(25.7))
),
child: new Directionality(
textDirection: TextDirection.ltr,
child: new TextField(
controller: null,
autofocus: false,
style:
new TextStyle(fontSize: 22.0, color: Color(0xFFbdc6cf)),
decoration: new InputDecoration(
filled: true,
fillColor: Colors.white,
hintText: 'Username',
contentPadding: const EdgeInsets.only(
left: 14.0, bottom: 8.0, top: 8.0),
focusedBorder: OutlineInputBorder(
borderSide: new BorderSide(color: Colors.white),
borderRadius: new BorderRadius.circular(25.7),
),
enabledBorder: UnderlineInputBorder(
borderSide: new BorderSide(color: Colors.white),
borderRadius: new BorderRadius.circular(25.7),
),
),
))),
It looks like it's caused by the splash effect on the textfield. I couldn't find a way to disable it for that specific widget but you can make it transparent by wrapping your TextField in a Theme widget and setting the splashColor to transparent:
Theme(
data: Theme.of(context).copyWith(splashColor: Colors.transparent),
child: TextField(
autofocus: false,
style: TextStyle(fontSize: 22.0, color: Color(0xFFbdc6cf)),
decoration: InputDecoration(
filled: true,
fillColor: Colors.white,
hintText: 'Username',
contentPadding:
const EdgeInsets.only(left: 14.0, bottom: 8.0, top: 8.0),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.white),
borderRadius: BorderRadius.circular(25.7),
),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.white),
borderRadius: BorderRadius.circular(25.7),
),
),
),
);
“Flutter Textfield background color”
*Change border color of TextField in flutter
TextFormField(
decoration: InputDecoration(
labelText: "Resevior Name",
fillColor: Colors.white,
focusedBorder:OutlineInputBorder(
borderSide: const BorderSide(color: Colors.white, width: 2.0),
borderRadius: BorderRadius.circular(25.0),
),
),
)
text fieldform color flutter
TextField(
style: TextStyle(color: Colors.red),
decoration: InputDecoration(fillColor: Colors.orange, filled: true),
)
Flutter TextFormField background color
TextFormField(
decoration: InputDecoration(
labelText: "Resevior Name",
fillColor: Colors.white,
filled: true, // dont forget this line
...
)
...
)
Flutter textfield label color
labelStyle: TextStyle(
color: Colors.white,
)
Color textfield text flutter
TextField(
style: TextStyle(color: Colors.white),
...
)
use BorderSide.none as:
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10.0),
borderSide: BorderSide.none,
),