I am trying to create a custom textfield so that i can easily change the design in one place only. The problem is, i don't know how to add onchange property in this custom textfield whenever it is provided. Can someone please show me how to do this. Fyi, this onchange property is optional. Below is my code.
Custom Textfield:
class CustomTextFieldOutline extends StatelessWidget {
CustomTextFieldOutline(
{@required this.label,
@required this.controller,
@required this.isObscureText,
@required this.isValid,
@required this.invalidMsg});
final String label;
final TextEditingController controller;
final bool isObscureText;
final bool isValid;
final String invalidMsg;
@override
Widget build(BuildContext context) {
return TextField(
decoration: InputDecoration(
labelText: label,
errorText: isValid ? null : invalidMsg,
errorStyle: TextStyle(color: constant.colorWhite),
labelStyle: TextStyle(color: constant.colorWhite),
errorBorder: UnderlineInputBorder(
borderSide: BorderSide(color: constant.colorWhite),
),
focusedErrorBorder: UnderlineInputBorder(
borderSide: BorderSide(color: constant.colorWhite),
),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: constant.colorWhite),
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: constant.colorWhite),
)),
style: TextStyle(color: constant.colorWhite),
controller: controller,
obscureText: isObscureText,
);
}
}
Textfield:
CustomTextFieldOutline(
label: constant.email,
controller: _emailSignUpController,
isValid: _isEmailValid,
invalidMsg: _emailValidMsg,
isObscureText: false,
)