I wrote this textformfield for userdata
TextFormField(
initialValue: datiUtente.peso.toString(),
validator: (val) =>
val.isEmpty ? 'inserisci il tuo peso' : null,
onChanged: (val) => setState(() => _currentPeso = val),
),
For name ed surname is ok, but if I want to use this for an int value how can I do it? I tried to like this but doesn't work
You can specify the number as keyboardType for the TextField using:
keyboardType: TextInputType.number
And your field code look like below,
TextFormField(
decoration: new InputDecoration(labelText: "Enter your number"),
keyboardType: TextInputType.number,
inputFormatters: <TextInputFormatter>[
FilteringTextInputFormatter.digitsOnly
], // Only numbers can be entered
validator: (val) => val.isEmpty ? 'inserisci il tuo peso' : null,
onChanged: (val) => setState(() => _currentPeso = val),
)
Pass the keyboardType as in TextInputType.number TextFormField:- keyboardType: TextInputType.number
Related
The named parameter 'onSubmitted' isn't defined.
Try correcting the name to an existing named parameter's name, or defining a named parameter with the name 'onSubmitted
My Code :
TextFormField(
onSubmitted: (value) {
},
controller: _passcon,
decoration: InputDecoration(
labelText: 'Password',
prefixIcon: Icon(Icons.lock)),
obscureText: true,
validator: (value) {
if (value!.isEmpty) {
return 'Please enter password';
}
return null;
},
onSaved: (value) => _password = value!,
),
please help me sir
You need to replace onSubmit with onFieldSubmitted.
It will fix your problem
the problem is as follows.
I implemented autofill to log-in fields. The function works very well on android and iOS. It turned out, however, that the password hint on a Pixel 4 phone isn't obscure.
Does anyone know how to fix this?
[Pixel 4 screenshot][1]
Update, code below:
AutofillGroup(
child: Column(
children: [
TextFormField(
autofillHints: [widget.signUpMode ? AutofillHints.newUsername : AutofillHints.username],
keyboardType: TextInputType.emailAddress,
autovalidateMode: AutovalidateMode.onUserInteraction,
validator: (String? value) {
if (value!.isEmpty) {
return S.of(context).formFieldValueRequiredLabel;
}
return null;
},
),
const SizedBox(height: 12),
if (widget.passwordController != null) ...[
TextFormField(
focusNode: passwordFocusNode,
autofillHints: [widget.signUpMode ? AutofillHints.newPassword : AutofillHints.password],
controller: widget.passwordController,
maxLength: 60,
obscureText: obscureText,
textAlign: TextAlign.center,
decoration: AppTheme.formFieldDecoration(),
style: AppTheme.formFieldStyleText,
keyboardType: TextInputType.text,
autovalidateMode: AutovalidateMode.onUserInteraction,
validator: (String? value) {
if (value!.isEmpty) {
return S.of(context).formFieldValueRequiredLabel;
}
return null;
},
)
],
],
),
)
Did you tried disabling the suggestions to Text Form Field like below
TextFormField(
obscureText: true,
enableSuggestions: false, // add this line
)
I have a login page but I only want the form to accept emails with a specific domain (e.g. #abc.net). Here is the code I have so far. How would I implement this?
Widget _showEmailInput() {
return new Padding(
padding: EdgeInsets.fromLTRB(15.0, 15.0, 15.0, 0.0),
child: TextFormField(
maxLines: 1,
keyboardType: TextInputType.emailAddress,
autofocus: false,
decoration: new InputDecoration(
hintText: 'Enter Email', icon: Icon(Icons.email, color: black)),
validator: (value) => value.isEmpty ? 'Email can not be empty' : null,
onSaved: (value) => _email = value.trim(),
));
}
Method 1
var isValid = value.toLowerCase().endsWith('your_domain.com');
Method 2 (RegEx)
validator: (value) {
if (value.isEmpty) return 'Email can not be empty'
var rx = RegExp("\b*#abc\.net\$",caseSensitive: false);
return rx.hasMatch(value) ? null : 'Invalid domain name';
}
Just replace abc.net to your desired domain name
print(rx.hasMatch('sdfsdf#sdf.net')); // false
print(rx.hasMatch('sdfsdf#abc.net')); // true
print(rx.hasMatch('sdfsdf#ABC.org')); // false
print(rx.hasMatch('sdfsdf#ABc.net')); // true
I just started learning Flutter and i am trying to figure out how the user can enter an amount in a TextField ,for example 1234567 , should look like this when user is typing :
1.00
12.00
123.00
1 234.00
12 345.00
123 456.00
1 234 567.00
I tried using this library : mask_text_input_formatter, but i can't figure out how to do it. Here is my code
var maskFormatter = new MaskTextInputFormatter(
mask: '### ### ###.00', filter: {"#": RegExp(r'[0-9]')});
TextFormField(
keyboardType: TextInputType.number,
inputFormatters: [maskFormatter],
onChanged: (value) {},
decoration: InputDecoration(
prefixIcon: Icon(Icons.monetization_on),
hintText: 'Amount',
border: OutlineInputBorder(),
),
validator: (value) {
if (value.isEmpty) {
return 'Please enter some text';
}
return null;
},
),
Any idea on how to achieve that result.
Declare and initialize a text controller and assign it to the text field. Update its value on change in input!
TextEditingController _moneyController = TextEditingController();
#override
void initState() {
super.initState();
_moneyController.text = '.00';
}
TextFormField(
keyboardType: TextInputType.number,
inputFormatters: [maskFormatter],
onChanged: (value) {},
decoration: InputDecoration(
prefixIcon: Icon(Icons.monetization_on),
hintText: 'Amount',
border: OutlineInputBorder(),
),
validator: (value) {
if (value.isEmpty) {
return 'Please enter some text';
}
return null;
},
//added code here
controller: _moneyController,
),
I have a text field that allows only digits. But when my user adds a new model then I need to preassign a value to the field numberOfPets.
Only 0-9 is allowed so I could use 0 but I would rather have an empty string in that text field but that is not possible as String is not a subtype of Int... I have also tried null but that is literally written as initialValue.
How would you display an empty string in that textfield ?
TextFormField(
keyboardType: TextInputType.number,
inputFormatters: [
LengthLimitingTextInputFormatter(3),
WhitelistingTextInputFormatter.digitsOnly,
],
decoration: const InputDecoration(
labelText: 'reps',
),
initialValue: widget.set.numberOfPets.toString() ,
validator: (value) {
return StringFieldValidator.validate(value);
},
onChanged: (value) {
setState(() {
widget.set.numberOfPets= int.parse(value);
});
},
),
Keep the numberOfPets as 0 but while assigning to initialValue check if 0 and change it to empty string
TextFormField(
keyboardType: TextInputType.number,
inputFormatters: [
LengthLimitingTextInputFormatter(3),
WhitelistingTextInputFormatter.digitsOnly,
],
decoration: const InputDecoration(
labelText: 'reps',
),
initialValue: widget.set.numberOfPets ==0 ? '' : widget.set.numberOfPets.toString() ,
validator: (value) {
return StringFieldValidator.validate(value);
},
onChanged: (value) {
setState(() {
widget.set.numberOfPets= int.parse(value);
});
},
),