mcnullable_extensions 0.2.0 copy "mcnullable_extensions: ^0.2.0" to clipboard
mcnullable_extensions: ^0.2.0 copied to clipboard

A collection of extensions to work with nullable types

mcnullable_extensions #

pipeline status MIT license PRs Welcome

A collection of extension methods to do less foo != null and more foo.isNotNull.

Usage - non-exhaustive list #

T? #

  • isNull
  • isNotNull
  • or('backup')
// isNull
expect(null.isNull, isTrue);

String? string;
expect(string.isNull, isTrue);

int? i;
expect(i.isNull, isTrue);

DumbCat? dumbCat;
expect(dumbCat.isNull, isTrue);

// isNotNull
num? n;
expect(n.isNotNull, isFalse);
num? n2 = 9;
expect(n2.isNotNull, isTrue);

DumbCat? dumbCat;
expect(dumbCat.isNotNull, isFalse);

// or
String? string;
expect(string.or('backup'), 'backup');

String? #

  • isNullOrEmpty
  • isNotNullOrEmpty
  • orEmptyString
// isNullOrEmpty
String? string;
expect(string.isNullOrEmpty, isTrue);

string = '';
expect(string.isNullOrEmpty, isTrue);

// orEmptyString
String? string;
expect(string.orEmptyString, '');

// isNotNullOrEmpty
String? string;
expect(string.isNotNullOrEmpty, isFalse);
expect(''.isNotNullOrEmpty, isFalse);

expect('words'.isNotNullOrEmpty, isTrue);
string = 'Hello Dart!';
expect(string.isNotNullOrEmpty, isTrue);
1
likes
120
points
137
downloads

Publisher

unverified uploader

Weekly Downloads

A collection of extensions to work with nullable types

Repository (GitLab)
View/report issues

Documentation

API reference

License

MIT (license)

More

Packages that depend on mcnullable_extensions