-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed as not planned
Labels
area-core-librarySDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.triage-automationSee https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot.See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot.type-enhancementA request for a change that isn't a bugA request for a change that isn't a bug
Description
Currently, there is no direct way to check if a nullable string is either null or empty ('') without writing verbose code. Adding an isNullOrEmpty getter for nullable string instances could simplify this common check and enhance code readability.
Example Usage:
String? str;
// Instead of writing:
if (str == null || str.isEmpty) {
// Do something
}
// With the proposed getter:
if (str.isNullOrEmpty) {
// Do something
}Benefits:
- Improved readability: Reduces boilerplate code and improves clarity.
- Consistency: Aligns with other commonly used utility methods in the Dart ecosystem.
- Ease of use: Provides a direct and intuitive way to handle nullable strings.
Implementation Consideration:
This getter could be implemented as an extension on String? to ensure minimal impact on existing codebases.
Example Implementation:
extension NullableStringExtensions on String? {
bool get isNullOrEmpty => this == null || this.isEmpty;
}This is how allot of peaple do this at the moment, this could be part of the sdk for conveniance.
I believe this feature would be a valuable addition to the Dart language.
I know this is a duplicate of (#11155) but that issue had aged over 13 years...
Metadata
Metadata
Assignees
Labels
area-core-librarySDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.triage-automationSee https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot.See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot.type-enhancementA request for a change that isn't a bugA request for a change that isn't a bug