I am completely new to flutter I have simple doubt how to check string value is zero or not in flutter using if condition.
Is there any property like isNotEmpty to check non zero value.
Thanks in advance for your help.
--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/5d46ee19-4b86-401d-8927-b509199e8fbb%40googlegroups.com.
Don't think you can call is Empty on a null variable. Will throw an error.
--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/8b658110-8bfc-4d9f-86da-52a9faa7907e%40googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/5d46ee19-4b86-401d-8927-b509199e8fbb%40googlegroups.com.
String s = null;
if (s == null) {
// Do something
}
To check if the String has no characters in it do
String s = '';
if (s.isEmpty) {
// Do something
}
To do both checks at the same time do
if (s?.isEmpty != false) {
// Do something
}
A little explanation on the third part. In Dart there are some so called null safe operations. These operations work if the variable is initialized but will not be called if they are null (it's an error to call a method on a null variable)
So calling s?.isEmpty means "if s is not null, call isEmpty on it, if it's null then don't call isEmpty and just return null".
This if has three possible values. It can be true or false (if s is not null) or it can be null (if s is null).
In your case, true and null are kind of equivalent (they both mean s holds no value to you) while false means s holds some value and thus isn't empty.
Hence the comparison "if (s?.isEmpty != false)".