BooleanConverter class

Converts arbitrary values to boolean values using extended conversion rules:

  • Numbers: <>0 are true, =0 are false
  • Strings: 'true', 'yes', 'T', 'Y', '1' are true; 'false', 'no', 'F', 'N' are false
  • DateTime: <>0 total milliseconds are true, =0 are false

Example

var value1 = BooleanConverter.toNullableBoolean(true); // true
var value2 = BooleanConverter.toNullableBoolean('yes'); // true
var value3 = BooleanConverter.toNullableBoolean(123); // true
var value4 = BooleanConverter.toNullableBoolean({}); // null

Constructors

BooleanConverter()

Properties

hashCode → int
The hash code for this object. [...]
read-only, inherited
runtimeType → Type
A representation of the runtime type of the object.
read-only, inherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
toString() → String
Returns a string representation of this object.
inherited

Operators

operator ==(dynamic other) → bool
The equality operator. [...]
inherited

Static Methods

toBoolean(dynamic value) → bool
Converts value into boolean or returns false when conversion is not possible. [...]
toBooleanWithDefault(dynamic value, bool defaultValue) → bool
Converts value into boolean or returns default value when conversion is not possible [...]
toNullableBoolean(dynamic value) → bool
Converts value into boolean or returns null when conversion is not possible. [...]