Fix MetadataFields text field values being lost in SupaEmailAuth widget (Fixes #113) #114
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.