asbool 1.0.0 copy "asbool: ^1.0.0" to clipboard
asbool: ^1.0.0 copied to clipboard

retractedoutdated

Simple tool to convert whatever thing (dynamic) to a bool value.

example/asbool_example.dart

import 'package:asbool/asbool.dart';

class MyClass {
  String? value = '';
}

class MyOtherClass extends MyClass {
  bool get isEmpty => value?.isEmpty ?? false;
}

void main() {
  
  assert(~null == !null.asBool); // true == true
  assert(asBool(null) == ~~0.0); // false == false
  assert(~null == true); // true == true
  assert(~'' == ~null); // true == true
  assert([23].asBool == true); // true == true
  assert(~~[] == false); // false == false
  assert(~~{} == false); // false == false
  assert(~~{'a': 'b'} == true); // true == true
  assert(~~double.nan == 0.asBool); // false == false
  assert(~~{2,4,5} == asBool(double.infinity)); // true == true

  assert(~'Hi' == false); // false == false
  assert('false'.asBool == true); // true == true

  assert(MyClass().asBool == true); // true == true
  assert(MyOtherClass().asBool == false); // false == false (with .isEmpty property)
  assert(asBool(MyOtherClass()..value='Hi') == true); // true == true (with .isEmpty property)


  print('All asserts OK');

  
}
3
likes
0
pub points
73%
popularity

Publisher

unverified uploader

Simple tool to convert whatever thing (dynamic) to a bool value.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

More

Packages that depend on asbool