Skip to content
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

Fix MetadataFields text field values being lost in SupaEmailAuth widget (Fixes #113) #114

Merged
merged 2 commits into from
Oct 1, 2024

Conversation

bcorman
Copy link
Contributor

@bcorman bcorman commented Oct 1, 2024

What kind of change does this PR introduce?

Fixes #113, where the values of text fields for MetadataFields on the SupaEmailAuth widget were getting lost, causing them to submit empty strings.

What is the current behavior?

The cause of the issue was how the SupaEmailAuth widget was storing TextEditingControllers for the MetadataFields in the map _metadataControllers, with an instance of the MetadataField being used as the key, with a TextEditingController as the value.

Later, in the build() method, the list of MetaDataFields were iterated upon, with each accessing its corresponding controller in the map. Unfortunately, at this point the MetadataField would be a separate instance with different hashkeys, so the original TextEditingController stored in the map would not be retrieved.

Flutter handles this failure silently; if a null value is passed to TextFormField.controller, then the text field just creates a new controller. However, on form submission, the _resolveMetadataFieldsData() method looks to the controllers stored in _metadataControllers, which would still contain empty strings.

What is the new behavior?

Update _SupaEmailAuthState to use MetadataField.key as map key instead of the MetadataField instance itself, and update related methods to work with new map structure.

Additional Notes

An earlier version of this change also added an equality operator override and a hashcode getter to the MetadataField class. Claude had insisted that both this change and the change to the map of controllers was necessary, however since we're no longer using MetadataField instances as keys, it's no longer necessary to compare them.

Implement == operator and hashCode getter in MetaDataField class
Update _SupaEmailAuthState to use MetaDataField.key as map key
Modify related methods to work with new map structure
Ensure consistent hashing and correct retrieval of TextEditingControllers
Resolve issue of losing metadata field values during widget lifecycle

This change prevents the loss of user input in custom metadata fields
by ensuring proper object equality and consistent map key usage.
Copy link
Member

@dshukertjr dshukertjr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, thanks for finding and fixing this issue!

@dshukertjr dshukertjr merged commit a5c75b8 into supabase-community:main Oct 1, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Metadata Fields in SupaEmailAuth Widget Losing Values
2 participants