toString1 function
Converts any object to a string if the object is not null
.
mirroring the same static method in the ConvertObject, providing alternative easy less code usage options.
- Converts various object types to their string representation.
- If the object is
null
, throws aParsingException
with anullObject
error. - If the conversion to string fails, throws a
ParsingException
.
object
The object to be converted to a string.
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 string if conversion is successful.
Throws a ParsingException
if the conversion fails or the object is null
.
Example usage:
final object1 = 'Hello';
final string1 = toString1(object1); // 'Hello'
final object2 = 10;
final string2 = toString1(object2); // '10'
final object3 = true;
final string3 = toString1(object3); // 'true'
final object4 = null;
final string4 = toString1(object4); // throws ParsingException
Implementation
String toString1(
dynamic object, {
Object? mapKey,
int? listIndex,
}) =>
ConvertObject.toString1(object, mapKey: mapKey, listIndex: listIndex);