toTryBool method

bool? toTryBool()

Tries to parse the string to a boolean. Returns true if string is 'true' (case-insensitive) or '1', false otherwise.

Example:

'true'.toTryBool();  // returns true
'1'.toTryBool();     // returns true
'false'.toTryBool(); // returns false
value?.toString().toTryBool(); // returns null or bool value

Implementation

bool? toTryBool() => bool.tryParse(toLowerCase()) ?? toTryInt() == 1;