'type 'String' is not a subtype of type 'DateTime?'
I get the following error when adding the date information returned from the item to the "tarih", "vadeTarihi" fields whose type is DateTime
type 'String' is not a subtype of type 'DateTime?'
masterDetailTemp = masterDetailTemp.copyWith(
master: masterDetailTemp.master!.copyWith(
// the line where i got the error
tarih: item.tarih,
vadeTarihi: item.vadeTarihi,
));
Type of values returned from item:
Solution 1:[1]
In your SatisFaturaMaster model class. Check the type of kayitTarihi and tarih variables if they are Strings then you need to parse the DateTime to convert it to a String.
To do that;
kayitTarihi.toString(); tarih.toString();
If you want to store tarih and vadeTarihi as DateTime do the following.
masterDetailTemp = masterDetailTemp.copyWith(
master: masterDetailTemp.master!.copyWith(
// the line where i got the error
tarih: DateTime.tryParse(item.tarih),
vadeTarihi: DateTime.tryParse(item.vadeTarihi),
));
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
