-
Notifications
You must be signed in to change notification settings - Fork 30.2k
Add 'onFocusChange' Property to TextFormField Widget #137020
Copy link
Copy link
Closed
Labels
r: solvedIssue is closed as solvedIssue is closed as solved
Description
Is there an existing issue for this?
- I have searched the existing issues
- I have read the guide to filing a bug
Use case
- Validation: Developers can use 'onFocusChange' to trigger input validation when a user leaves the field, providing immediate feedback on the entered data.
- User Experience: It enables custom behaviors, like scrolling the view to keep the focused field visible when the keyboard appears.
- Accessibility: For making apps more accessible, it's necessary to handle focus changes to notify screen readers or provide auditory feedback.
Proposal
Change the color of the eye icon in a password field when the user leaves the TextFormField to provide visual feedback on focus changes.
TextFormField(
obscureText: _isObscure && widget.isPassword,
decoration: InputDecoration(
border: const UnderlineInputBorder(
borderSide: BorderSide(color: grey),
),
focusedBorder: const UnderlineInputBorder(
borderSide: BorderSide(color: primaryColor),
),
labelText: widget.hintText,
labelStyle: Theme.of(context).textTheme.labelSmall!.copyWith(
color: Colors.black,
),
suffixIcon: widget.isPassword
? IconButton(
icon: Icon(
_isObscure ? Icons.visibility : Icons.visibility_off,
color: _isFocused ? primaryColor : Colors.grey,
),
onPressed: _toggleObscure,
)
: null,
),
style: TextStyle(color: Colors.black),
validator: (value) {
if (value == null || value.isEmpty) {
return 'Please enter a value';
}
return null;
},
onSaved: (value) {
// Do something with the value
},
// _handleFocus handle change of eye color
onFocusChange: _handleFocus,
);
Android.Emulator.-.Pixel_3a_API_34_extension_level_7_x86_64_5554.2023-10-21.20-57-25.mp4
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
r: solvedIssue is closed as solvedIssue is closed as solved