I have a TextFormField
and I want to change the background color from #EFEFEF to white when the user presses on the field to type, here is my custom widget:
class TextFieldWidget extends StatelessWidget {
final TextEditingController controller;
final bool isEmail;
const TextFieldWidget({
Key? key,
required this.controller,
required this.isEmail,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return TextFormField(
keyboardType: isEmail ? TextInputType.emailAddress : TextInputType.text,
obscureText: !isEmail,
controller: controller,
decoration: InputDecoration(
hintText: isEmail ? 'Enter your email' : 'Enter your password',
filled: true,
fillColor: const Color(0xffefefef),
focusColor: Colors.white,
border: OutlineInputBorder(borderRadius: BorderRadius.circular(5)),
prefixIcon: Icon(
isEmail ? Icons.email : Icons.lock,
color: const Color(0xFF1273EB),
),
),
validator: (value) {
if (isEmail) {
if (value!.isEmpty) {
return 'Email can\'t be empty';
} else if (!value.contains('@')) {
return 'Please enter a valid email address';
}
} else if (!isEmail) {
if (value!.isEmpty) {
return 'Password can\'t be empty';
} else if (value.length < 6) {
return 'Password must be at least 6 characters long';
}
}
return null;
},
);
}
}
When the screen displays I have the #EFEFEF color, but when I press on the text field it doesn't turn to another color (white in my case).