toDateTime function
Attempts to convert an object to a bool, or returns null if the object is null or conversion is not applicable.
mirroring the same static method in the ConvertObject, providing alternative easy less code usage options.
- Returns
trueif the object is abooland equal totrue. - Returns
trueif the object is aStringand equal to 'yes' or 'true' (case-insensitive). - Returns
nullfor other types or if the object isnull.
object The object to be converted to a bool.
mapKey (Optional) Specifies the key to extract values from a Map object.
listIndex (Optional) Specifies the index to extract elements from a List object.
Returns a bool if conversion is applicable, otherwise null.
Example usage:
final object1 = true;
final bool1 = tryToBool(object1); // true
final object2 = 'yes';
final bool2 = tryToBool(object2); // true
final object3 = 10;
final bool3 = tryToBool(object3); // null
final object4 = false;
final bool4 = tryToBool(object4); // false
final object5 = 'no';
final bool5 = tryToBool(object5); // false
final object6 = null;
final bool6 = tryToBool(object6); // null
Implementation
DateTime toDateTime(
dynamic object, {
dynamic mapKey,
int? listIndex,
String? format,
String? locale,
bool autoDetectFormat = false,
bool useCurrentLocale = false,
bool utc = false,
DateTime? defaultValue,
}) =>
ConvertObject.toDateTime(
object,
mapKey: mapKey,
listIndex: listIndex,
format: format,
locale: locale,
autoDetectFormat: autoDetectFormat,
useCurrentLocale: useCurrentLocale,
utc: utc,
defaultValue: defaultValue,
);