Dart – Check if String is Empty
To check if given String is empty in Dart, read isEmpty property of this String. isEmpty is read only property that returns a boolean value of true if the String is empty, or false if the String is not empty.
Syntax
The syntax to read isEmpty property of a string is
</>
                        Copy
                        String.isEmptyExamples
Empty String
In this example, we will take an empty String and programmatically check if this string is empty or not.
main.dart
</>
                        Copy
                        void main() {
  var str = '';
  if (str.isEmpty) {
    print('String is empty.');
  } else {
    print('String is not empty.');
  }
}Output
String is empty.Non Empty String
In this example, we will take an non-empty String and programmatically check if this string is empty or not.
main.dart
</>
                        Copy
                        void main() {
  var str = 'Hello World!';
  if (str.isEmpty) {
    print('String is empty.');
  } else {
    print('String is not empty.');
  }
}Output
String is not empty.Conclusion
In this Dart Tutorial, we learned how to check if given string is empty, using isEmpty property of String class object, with examples.
