How to disable number keys on keyboard? - flutter

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")),
],

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),
),

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),
)
),
),

Flutter "Hint Text" Animation

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),
),

Flutter | How to always keep Text Field in focus(Keep show cursor)

Here, I've one text field which I want to keep always in focus and I don't want to open keyboard when the text field is clicked. in short text field always needs to be in focus.
Here is the my text field code.
TextFormField(
style: TextStyle(
color: Colors.white,
fontSize: orientation == Orientation.portrait
? MediaQuery.of(context).size.width * 0.030
: MediaQuery.of(context).size.width * 0.020,
),
validator: (val) => Validators.validateRequired(
val, " Product Baarcode"
),
controller: _addproduct,
decoration: InputDecoration(
errorStyle: TextStyle(color: Colors.yellow),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.white),
),
fillColor: Colors.white,
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.white),
),
hintStyle: TextStyle(color: Colors.white),
labelStyle: TextStyle(color: Colors.white),
filled: false,
prefixIcon: Icon(
FontAwesomeIcons.barcode,
color: Colors.white,
),
labelText: "Enter Product Barcode",
hintText: "Enter Product Barcode",
),
onFieldSubmitted: (val) {
_addProduct();
},
),
You can set the autofocus property to true so that the cursor will start showing as soon as the app starts.
For more info please refer to this link
TextField(
autofocus: true,
)

How to add an extra label within TextFormField?

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,
),