Skip to content

Commit

Permalink
Fix MetadataFields text field values being lost in SupaEmailAuth widg…
Browse files Browse the repository at this point in the history
…et (Fixes #113) (#114)

* Fix metadata field value persistence in SupaEmailAuth widget

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.

* Remove unecessary equality operator override and hashcode getter.
  • Loading branch information
bcorman authored Oct 1, 2024
1 parent 1d7c37c commit a5c75b8
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/src/components/supa_email_auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class _SupaEmailAuthState extends State<SupaEmailAuth> {
final _formKey = GlobalKey<FormState>();
final _emailController = TextEditingController();
final _passwordController = TextEditingController();
late final Map<MetaDataField, TextEditingController> _metadataControllers;
late final Map<String, TextEditingController> _metadataControllers;

bool _isLoading = false;

Expand All @@ -142,7 +142,8 @@ class _SupaEmailAuthState extends State<SupaEmailAuth> {
void initState() {
super.initState();
_metadataControllers = Map.fromEntries((widget.metadataFields ?? []).map(
(metadataField) => MapEntry(metadataField, TextEditingController())));
(metadataField) =>
MapEntry(metadataField.key, TextEditingController())));
}

@override
Expand Down Expand Up @@ -225,7 +226,7 @@ class _SupaEmailAuthState extends State<SupaEmailAuth> {
...widget.metadataFields!
.map((metadataField) => [
TextFormField(
controller: _metadataControllers[metadataField],
controller: _metadataControllers[metadataField.key],
textInputAction:
widget.metadataFields!.last == metadataField
? TextInputAction.done
Expand Down Expand Up @@ -423,8 +424,7 @@ class _SupaEmailAuthState extends State<SupaEmailAuth> {
Map<String, dynamic> _resolveMetadataFieldsData() {
return widget.metadataFields != null
? _metadataControllers.map<String, dynamic>(
(metaDataField, controller) =>
MapEntry(metaDataField.key, controller.text))
(key, controller) => MapEntry(key, controller.text))
: <String, dynamic>{};
}
}

0 comments on commit a5c75b8

Please sign in to comment.