First I have a file named ‘common.dart’ with:
enum FieldType {
string,
float
int,
text,
boolean,
date
time,
dateTime,
files,
password. password
}
And the file named ‘dynamic.dart’ uses FieldType for type :
FieldDefine(
name: 'password', type: FieldType.string.index, caption: 'Password').
As you can see when I change: FieldType.string.index
to FieldType.password.index
the code does not work, but FieldType.string.index
does work and error message is wrong password. I think when the password the user enters in the password box from the beginning it is of string type and when the user presses the submit button it works because it is the same data type, and when I switch to the password type it is a different data type so then it says wrong password error.
Here is the code to display the password box:
Column(
children: [
TextFormField(
obscureText: _isObscure,
decoration: InputDecoration(
label: RichText(
text: TextSpan(
text: 'Password ',
style: TextStyle(color: Colors.black),
children: [
TextSpan(
text: '(*)',
style: TextStyle(color: Colors.red[900]),
),
TextSpan(text: ' '),
],
),
),
suffixIcon: IconButton(
onPressed: () {
setState(() {
_isObscure = !_isObscure;
});
},
icon: Column(
children: [
Icon(_isObscure ? Icons.visibility : Icons.visibility_off
// Use ternary operator
),
],
),
),
hintText: "Input The Password",
),
keyboardType: TextInputType.text,
inputFormatters: [
FilteringTextInputFormatter.allow(RegExp(r'[a-zA-Z0-9]')),
],
validator: (value) {
if (value == null || value.isEmpty) {
return 'Please enter a password';
}
if (!RegExp(r'^[a-zA-Z0-9]+$').hasMatch(value)) {
return 'Password must contain only letters and numbers';
}
return null;
},
),
],
);
I haven’t tried much because I’m not sure where it’s going wrong. How can I resolve it?
hoang le is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.