This commit is contained in:
2025-03-25 13:49:02 +01:00
parent 44e26460d8
commit d2bb65a91e
12 changed files with 546 additions and 6 deletions
+38
View File
@@ -44,3 +44,41 @@ extension Unique<E, Id> on List<E> {
return list;
}
}
/// An extension on nullable `List` to provide convenience methods for checking nullability and emptiness.
///
/// This extension adds getters that make it easier to check if a list is null,
/// empty, or both in a single operation.
extension ListNullability on List? {
/// Returns `true` if the list is either not null and not empty.
///
/// This is the inverse of [isNullOrEmpty].
///
/// Example usage:
/// ```dart
/// List<int>? list = [1, 2, 3];
/// print(list.isNotNullOrEmpty); // Output: true
///
/// list = [];
/// print(list.isNotNullOrEmpty); // Output: false
///
/// list = null;
/// print(list.isNotNullOrEmpty); // Output: false
/// ```
bool get isNotNullOrEmpty => !isNullOrEmpty;
/// Returns `true` if the list is either null or empty.
///
/// Example usage:
/// ```dart
/// List<int>? list = null;
/// print(list.isNullOrEmpty); // Output: true
///
/// list = [];
/// print(list.isNullOrEmpty); // Output: true
///
/// list = [1, 2, 3];
/// print(list.isNullOrEmpty); // Output: false
/// ```
bool get isNullOrEmpty => this == null || this!.isEmpty;
}
+1 -1
View File
@@ -27,7 +27,7 @@ class Ticker {
required Duration timeout,
Duration interval = const Duration(seconds: 1),
}) {
final int ticks = timeout.inSeconds ~/ interval.inSeconds;
final int ticks = timeout.inMicroseconds ~/ interval.inMicroseconds;
return Stream.periodic(interval, (x) => ticks - x - 1).take(ticks);
}
}