Update documentation

Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
2024-10-04 14:29:58 +02:00
parent 89e49d60e8
commit 74b1c7940b
4 changed files with 69 additions and 7 deletions
+26 -2
View File
@@ -10,11 +10,35 @@ abstract class CommonString {
static const String bulletPoint = "";
}
/// An extension that adds convenience methods to handle nullability and
/// emptiness checks for `String?` types.
extension Nullability on String? {
/// Returns `true` if the `String?` is neither `null` nor only contains whitespace.
/// Returns `true` if the `String?` is neither `null` nor contains only whitespace.
///
/// This is useful for cases where you want to check if a nullable string has a valid
/// non-empty, non-whitespace value.
///
/// Example usage:
/// ```dart
/// String? example = "Hello";
/// if (example.isNotNullOrEmpty) {
/// print("The string is not null and not empty");
/// }
/// ```
bool get isNotNullOrEmpty => !isNullOrEmpty;
/// Returns `true` if the `String?` is either `null` or contains only whitespace.
/// Returns `true` if the `String?` is either `null` or contains only whitespace.
///
/// This is a handy utility to check if a nullable string is either not assigned
/// or effectively empty (including strings with only whitespace characters).
///
/// Example usage:
/// ```dart
/// String? example = null;
/// if (example.isNullOrEmpty) {
/// print("The string is null or empty");
/// }
/// ```
bool get isNullOrEmpty => this == null || (this ?? "").trim().isEmpty;
}