[Solved]: type ‘String’ is not a subtype of type ‘DateTime’ in type cast

type ‘String’ is not a subtype of type ‘DateTime’ in type cast

When you are working with date time in Flutter, sometimes you might get an error: type ‘String’ is not a subtype of type ‘DateTime’ in type cast. Usually, it happens when you retrieve a date from the database and pass the data to a DateTime as a string. 

Solution: use DateTime.parse()

To solve this error, you have to convert string type to DateTime type using: DateTime.parse(string)

DateTime.parse(string)

You May Also Like

Leave a Reply

Your email address will not be published.

4 × 1 =