Home > OS >  type 'String' is not a subtype of type 'DateTime?'
type 'String' is not a subtype of type 'DateTime?'

Time:02-26

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:

enter image description here

CodePudding user response:

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),
    ));

CodePudding user response:

this worked:

tarih: DateTime.tryParse(item.tarih.toString()),
vadeTarihi: DateTime.tryParse(item.vadeTarihi.toString()),
  • Related