changeTo<R> method
Converts a value of type Object
to a specified type T
.
This function can convert between bool
, DateTime
, num
, int
, double
, and String
types.
It assumes that the input is in a format that can be parsed to the desired type.
return null if the conversion is not possible.
Usage:
print(changeTo<int>('123')); // prints: 123
print(changeTo<double>('123.45')); // prints: 123.45
print(changeTo<DateTime>('2024-05-27 13:18:56')); // prints: 2024-05-27 13:18:56.000
print(changeTo<String>(123)); // prints: '123'
print(changeTo<bool>('y')); // prints: true
T
The type to convert the value to.
value
The value to convert.
Returns the converted value of type T
.
Implementation
R changeTo<R>() => _changeTo<R>(this);