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.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object 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.