-
Notifications
You must be signed in to change notification settings - Fork 269
feat(authenticator): Add TextEditingController support to form fields #6424
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…elds - Introduced AuthenticatorTextFieldController for programmatic control over text fields. - Updated mixins (AuthenticatorTextField, AuthenticatorUsernameField) to utilize the new controller. - Enhanced various form fields (ConfirmSignIn, ConfirmSignUp, EmailSetup, PhoneNumber, ResetPassword, SignIn, SignUp, VerifyUser) to accept and manage TextEditingController. - Added tests to ensure synchronization between form fields and their respective controllers.
…e sync timing - Add nullable controller getter to AuthenticatorFormField and include it in diagnostics - Add debugFillProperties implementations to form field widgets to surface the controller prop - Rework text controller sync logic in AuthenticatorTextField and AuthenticatorUsernameField: - Skip syncing in initState and avoid syncing during build - Schedule post-frame callbacks in didChangeDependencies to first apply controller->state (if controller has initial text) then sync state->controller - Minor conditional/formatting cleanup in username field sync
…tingController support for form fields - Export AuthenticatorTextFieldController from package API. - Integrate optional controller parameter into prebuilt form fields (sign-in, sign-up, confirm, reset password, verify user, email setup, etc.) with proper diagnostics. - Ensure bidirectional sync between controllers and internal authenticator state. - Add example demonstrating controller usage and pre-population (examples/authenticator_with_controllers.dart). - Add comprehensive widget tests for controller <-> state synchronization, standard TextEditingController compatibility, and rapid updates. - Update CHANGELOG with 2.4.0 notes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds TextEditingController support to Amplify Authenticator form fields, enabling programmatic control over form field values. This feature allows developers to pre-populate fields with data from external sources (e.g., GPS, APIs) or auto-fill verification codes.
- Introduces
AuthenticatorTextFieldControlleras a FlutterTextEditingControllerwrapper - Adds optional
controllerparameter to all text-based form fields across sign-in, sign-up, verification, and password reset flows - Implements bidirectional synchronization between controllers and internal authenticator state
Reviewed Changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| authenticator_text_field_controller.dart | New controller class extending TextEditingController for authenticator fields |
| authenticator_text_field.dart | Adds controller sync logic to text field mixin with lifecycle management |
| authenticator_username_field.dart | Adds controller sync logic to username field mixin, handling phone number special case |
| sign_in_form_field.dart | Adds controller parameter to sign-in fields (username, password) |
| sign_up_form_field.dart | Adds controller parameter to sign-up fields (username, password, email, address, name, phone, etc.) |
| confirm_sign_in_form_field.dart | Adds controller parameter to confirm sign-in fields (password, verification code, attributes) |
| confirm_sign_up_form_field.dart | Adds controller parameter to confirm sign-up fields (username, verification code) |
| reset_password_form_field.dart | Adds controller parameter to reset password fields (verification code, new password, confirmation) |
| verify_user_form_field.dart | Adds controller parameter to user verification field |
| email_setup_form_field.dart | Adds controller parameter to email setup field |
| phone_number_field.dart | Adds controller parameter to phone number field |
| form_field.dart | Adds controller getter to base form field class |
| form_field_controller_test.dart | Comprehensive test suite validating controller sync behavior |
| authenticator_with_controllers.dart | Example app demonstrating controller usage |
| amplify_authenticator.dart | Exports the new AuthenticatorTextFieldController |
| CHANGELOG.md | Documents the new feature |
| main.dart | Adds commented example reference |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
packages/authenticator/amplify_authenticator/lib/src/mixins/authenticator_username_field.dart
Show resolved
Hide resolved
packages/authenticator/amplify_authenticator/example/lib/authenticator_with_controllers.dart
Show resolved
Hide resolved
… stabilize sync Buffer controller changes and apply them in a post-frame callback to avoid calling setState during build. Normalize trailing whitespace when comparing controller and state to reduce unnecessary writes. Ensure didUpdateWidget sync runs after build and clear pending state on dispose. Add widget tests covering typing, special keys, rapid updates, and controller interactions.
|
@tyllark could you please review? |
- Add enabledOverride and visible to AuthenticatorFormField and include in diagnostics - Use enabledOverride to determine enabled state; honor override in ConfirmSignUpFormField - Render hidden fields offstage with Visibility maintaining state (so programmatic updates still sync) - Propagate enabled/visible through SignUpFormField factory APIs and concrete field constructors - Add tests verifying disabled fields still sync with controllers and hidden fields retain state synchronization
|
Here is a real world usage of this PR, it also uses the hide functionality to hide and automatically fill the Address field of aws cognito using the other address info available on the form. Video2.mp4 |
This PR adds
TextEditingControllersupport to Amplify Authenticator form fields, enabling developers to programmatically control text input fields during authentication flows. It also introduces per-field visibility and enabled-state overrides for Sign Up fields so apps can keep legacy attributes off-screen or block user edits while still syncing values via controllers.cc: @tyllark
What was changed
AuthenticatorTextFieldControllerclass that wraps Flutter'sTextEditingControllerwith identical semantics.controllerparameter to all text-based form fields across all authentication steps:visible(defaulttrue) andenabledoverrides to everySignUpFormFieldfactory so applications can hide fields while keeping controller updates, or disable manual editing for attributes filled from background processes.controller,enabled, andvisiblevalues.Why was this change made
Addresses the need for programmatic control over authenticator form fields to enable use cases such as:
How was this change tested
TextEditingControllercompatibilityauthenticator_with_controllers.dart) demonstrating real-world usage patternsRelated Issues
Fixes #6161
Migration Guide
This is a non-breaking change. Existing code continues to work without modifications. To use the new controller functionality:
Standard
TextEditingControlleris also supported for flexibility.Screenshots/Videos
Video.mp4
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.