fredeil / email-validator.dart

A simple Dart class for validating email addresses (syntax) without using RegEx :email:
https://pub.dartlang.org/packages/email_validator
MIT License
195 stars 38 forks source link

Warning: Operand of null-aware operation '!' has type 'String' which excludes null. #35

Closed aaronkelton closed 2 years ago

aaronkelton commented 2 years ago

Before adding null check

When using the TextFormField's validator parameter, passing the value to EmailValidator.validate() warns that I need to Add a null check (!). Screenshot showing the warning with suggested fix.

CleanShot 2021-11-16 at 08 03 39@2x

After adding null check (plus print statement)

However, if I add the null check bang, and try to print the result of EmailValidator.validate(value!), I get a different warning:

Warning: Operand of null-aware operation '!' has type 'String' which excludes null.
CleanShot 2021-11-16 at 08 04 57@2x

Question

Is this warning something that should be fixed in this email-validator package? The Stack Overflow posts I've read for this warning from other packages indicated that a fix was necessary in the package's code. E.g. https://stackoverflow.com/questions/67389956/why-im-getting-this-error-warning-operand-of-null-aware-operation-has-type

fredeil commented 2 years ago

Are you using the latest version? This package has impemented null-safety for quite some time.

I’m not sure if others are experiencing the same issue or not. I will look into the stackoverflow post to see if this affects the code.. @aaronkelton

aaronkelton commented 2 years ago

Version 2.0.1

I wish I had a better understanding of Dart and null-safety to understand this error message. I can get the error to disappear by changing the print line to use double question marks instead of bang:

print(EmailValidator.validate(value ?? ''));

I don't know if:

  1. I'm using value! incorrectly per Dart best practices, or
  2. There is some change that should be made in this package, or
  3. There is some needed change to the TextFormField widget.

Maybe banging a variable more than once is the issue. 🤷‍♂️ Thank you for considering my issue! ❤️