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

Errors map unmodifiable causing nasty exceptions #437

Open
air-hedgehog opened this issue Jan 13, 2024 · 1 comment
Open

Errors map unmodifiable causing nasty exceptions #437

air-hedgehog opened this issue Jan 13, 2024 · 1 comment

Comments

@air-hedgehog
Copy link

Hi, I would like to introduce a humble suggestion, regarding returned errors from models.dart

someControl.setErrors(<String, dynamic>{ ...someControl.errors ..removeWhere((key, value) => key == errorMessageKey), });
When used like that it causes exception due to unmodifiable Map returned.
Wouldn't it be more convenient to return copy of the map:
Map<String, Object> get errors => Map<String, Object>.from(_errors);
instead of:
Map<String, Object> get errors => Map<String, Object>.unmodifiable(_errors);

P.S. Yeah, I am aware now of someControl(errorMessageKey); but only after this error of mine was merged)

@joanpablo
Copy link
Owner

Hi @air-hedgehog,

Thanks for your feedback. I see what's your point, and it makes sense. I believe the initial idea of using unmodifiable collections was to remove the false impression that someone could change the original collection of errors. On the other hand you can also create a copy of the errors, and that will solve your problem. This would do the trick:

final myErrors = {...control.errors}..removeWhere((key, value) => key == errorMessageKey);

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

No branches or pull requests

2 participants