How to add an extra label within TextFormField? - flutter

Is there a way to position "Forget password" label inside a TextFormField?
On a sample picture put forget password? right inside the input
new TextFormField(
decoration: InputDecoration(labelText: 'Password',
labelStyle: TextStyle(
color: Colors.black87,
fontSize: 17,
fontFamily: 'AvenirLight'
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.purple),
),
enabledBorder: new UnderlineInputBorder(
borderSide: BorderSide(color: Colors.grey,
width: 1.0)
),
),
style: TextStyle(
color: Colors.black87,
fontSize: 17,
fontFamily: 'AvenirLight'
),
controller: _passwordController,
obscureText: true,
),

use the Suffix: property of - InputDecoration:
TextFormField(
decoration: InputDecoration(
suffix: GestureDetector(
onTap: () {
print('tapped');
},
child: Text(
'Forgot Password?',
style: TextStyle(
color: Colors.blue, fontWeight: FontWeight.bold),
),
),
labelText: 'Password',
labelStyle: TextStyle(
color: Colors.black87,
fontSize: 17,
fontFamily: 'AvenirLight'),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.purple),
),
enabledBorder: new UnderlineInputBorder(
borderSide: BorderSide(color: Colors.grey, width: 1.0)),
),
style: TextStyle(
color: Colors.black87, fontSize: 17, fontFamily: 'AvenirLight'),
// controller: _passwordController,
obscureText: true,
),

Related

flutter how remove text underline on text selection (TextFormField)?

It is necessary to move the cursor to the end of the text, but in flutter this is strangely implemented through text selection, I do it like this
textController.selection =
TextSelection.collapsed(offset: textController.text.length);
it works, but when typing, it appears underlined
It is possible to somehow remove the underlining of the text, I read the documentation, but did not find it.
My TextFormField
TextFormField(
cursorColor: Colors.white,
style: const TextStyle(
color: Colors.white,
fontSize: 20,
),
controller: textController,
autofocus: false,
decoration: const InputDecoration(
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.white)),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.white)),
filled: true,
isDense: true,
hintText:
'search',
hintStyle: TextStyle(
//Style of hintText
color: Colors.white60,
fontSize: 20,
),
),
),
This might help you:
TextField(
style: const TextStyle(
decoration: TextDecoration.none),
),

Flutter: Align TextField text in a larger container

I can align the hint text to the center with no issues, but when the user starts typing into the textbox, I can't seem to get it to align to the center.
When maxLines are set to 1, there isn't an issue, but when it is set to more than 1 (or to null in my case), then it seems to align to the top by default.
Screenshot1
Screenshot2
Is there any way to correct this?
Container(
width: screenWidth / 1.2,
height: 120,
padding:
EdgeInsets.symmetric(horizontal: 0),
child: TextField(
// autofocus: false,
controller: postText,
keyboardType: TextInputType.text,
maxLines: 10,
textAlign: TextAlign.center,
textAlignVertical:
TextAlignVertical.center,
style: TextStyle(
fontFamily: 'Michroma',
color: selectedFont,
fontSize: 12, // 12
),
decoration: InputDecoration(
hintText: '\n\nType away ! :\n\n\n',
hintStyle: TextStyle(
color: fontColour,
fontFamily: 'Michroma',
fontWeight: FontWeight.bold,
fontSize: 12,
),
filled: true,
fillColor: screenColour,
contentPadding: EdgeInsets.symmetric(
vertical: 8.0,
horizontal: 10.0,
),
border: OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(20.0),
), // 32
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
color: borderColour,
width: 1.0,
),
borderRadius: BorderRadius.all(
Radius.circular(20.0),
), // 32
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: borderColour,
width: 2.0,
),
borderRadius: BorderRadius.all(
Radius.circular(20.0),
), // 32
),
),
),
),
You need to delete \n\n expression in front of the hint text value because \n provides us to switch to a new line.
In your case, you switch the line you in two times. That is why the hint text is not appearing where you type.
decoration: InputDecoration(
hintText: 'Type away ! :', <--- here
hintStyle: TextStyle(
color: fontColour,
fontFamily: 'Michroma',
fontWeight: FontWeight.bold,
fontSize: 12),
When you remove that expression, probably it will not be in the center. so you can center it by doing following;
child: TextField(
controller: postTextController,
keyboardType: TextInputType.multiline,
textAlign: TextAlign.center,
maxLines: null,
expands: true,
textAlignVertical: TextAlignVertical.center,
style: TextStyle(
fontFamily: 'Michroma',
fontSize: 12),
decoration: InputDecoration(
hintText: 'Type away ! :',
hintStyle: TextStyle(
fontFamily: 'Michroma',
fontWeight: FontWeight.bold,
fontSize: 12),

add padding to TextField cursor / center the TextField cursor in flutter

I have a TextField and when i change cursor height it comes down . i want it come center or add padding under it.
Cursor should be vertically center of TextField is that possible ?
and this is my code.
TextField(
cursorHeight: 30,
cursorColor: Colors.yellow,
cursorWidth: 2,
cursorRadius: Radius.circular(500),
style: TextStyle(color: Colors.white, fontSize: 14),
obscureText: isPasswordTextField ? showPassword : false,
decoration: InputDecoration(
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.transparent),
borderRadius: BorderRadius.all(Radius.circular(8)),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(width: 2, color: Colors.yellow),
borderRadius: BorderRadius.circular(10),
),
suffixIcon: isPasswordTextField
? IconButton(
onPressed: () {
setState(() {
showPassword = !showPassword;
});
},
icon: Icon(
Icons.remove_red_eye,
color: Colors.yellow,
),
)
: null,
contentPadding: EdgeInsets.fromLTRB(10, 0, 0, 0),
filled: true,
fillColor: Color.fromRGBO(28, 28, 28, 1),
labelText: labelText,
labelStyle: TextStyle(
color: Colors.yellow,
fontSize: 22,
fontFamily: 'Exo',
fontWeight: FontWeight.bold
),
floatingLabelBehavior: FloatingLabelBehavior.always,
hoverColor: Color.fromRGBO(54, 54, 54, 1),
hintText: placeholder,
hintStyle: TextStyle(
fontSize: 14,
color: Colors.white,
)
),
),
This should help. As you can see in the your textfiled there is no height specified.
TextField(
cursorHeight: 30,
cursorColor: Colors.yellow,
cursorWidth: 2,
cursorRadius:const Radius.circular(500),
style: TextStyle(
color: Colors.white,
fontSize: 14,
height: 1.5 //Add this
),
),
Try below code hope its helpful to you.add your extra code also I tried to design
TextField(
style: TextStyle(
color: Colors.white,
fontSize: 14,
),
decoration: InputDecoration(
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.transparent),
borderRadius: BorderRadius.all(
Radius.circular(8),
),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
width: 2,
color: Colors.yellow,
),
borderRadius: BorderRadius.circular(10),
),
suffixIcon: IconButton(
onPressed: () {
setState(() {});
},
icon: Icon(
Icons.remove_red_eye,
color: Colors.yellow,
),
),
// floatingLabelBehavior: FloatingLabelBehavior.always,
contentPadding: EdgeInsets.fromLTRB(10, 0, 0, 0),
filled: true,
fillColor: Color.fromRGBO(28, 28, 28, 1),
labelText: 'labelText',
labelStyle: TextStyle(
color: Colors.yellow,
fontSize: 22,
fontFamily: 'Exo',
fontWeight: FontWeight.bold),
hoverColor: Color.fromRGBO(54, 54, 54, 1),
hintText: 'placeholder',
hintStyle: TextStyle(
fontSize: 14,
color: Colors.white,
),
),
),
Your result screen->

How to disable number keys on keyboard?

Like I want to use the Textfield only for text only, not numbers. So how to disable that?
title: TextField(
textCapitalization: TextCapitalization.sentences,
style: TextStyle(color: Colors.white),
controller: searchController,
decoration: InputDecoration(
hintText: 'Search for staff name',
hintStyle:
TextStyle(color: Colors.white, fontWeight: FontWeight.w400),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.white),
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.white),
),
filled: true,
enabled: true,
prefixIcon: Icon(
Icons.person_pin,
color: Colors.white,
size: 30,
),
suffixIcon: IconButton(
icon: Icon(Icons.clear, color: Colors.white),
onPressed: emptyTheTextformfield,
)),
),
Try this
inputFormatters: <TextInputFormatter>[
WhitelistingTextInputFormatter(RegExp(r"[a-zA-Z]+|\s")),
],

TextSelectionThemeData is not changing selectionHandleColor in flutter

Tested on Both physical device and simulator.
As we all know textSelectionHandleColor is deprecated. So, I decided to make some changes in my app code, unfortunately, selectionHandleColor is still default blue color we get, when we create new app.
TextSelectionTheme(
data: TextSelectionThemeData(
cursorColor: kLightGreen,
selectionHandleColor: kLightGreen,
selectionColor: kGrey),
child: TextField(
keyboardType: TextInputType.number,
style: TextStyle(
color: kOffWhite,
letterSpacing: 1.5,
),
decoration: InputDecoration(
labelText: 'Label',
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: kLightGreen),
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: kLightGreen),
),
hintText: 'Hint',
hintStyle: TextStyle(
color: kOffWhite,
letterSpacing: 1.5,
),
labelStyle: TextStyle(
color: kLightGreen,
letterSpacing: 1.5,
),
),
),
),
Cursor color, selection color got changed except handle color. I have tried every possible way to change text selection handle color.