Home > Software engineering >  Flutter: type 'DateTime' is not a subtype of type 'String'
Flutter: type 'DateTime' is not a subtype of type 'String'

Time:09-28

Text(
        DateTime.parse(documents[index]['createdAt']
                                  .toDate()
                                  .toString()) ??
                              'default',
)

I am trying to get date from firestore. I have DateTime.now() stored in createdIn in firestore.

CodePudding user response:

because the format of both is not the same.

  1. step 1: you can create DateFormat.
  2. step 2: use 'DateFormat'.parse().

try reading this: https://help.talend.com/r/6K8Ti_j8LkR03kjthAW6fg/atMe2rRCZqDW_Xjxy2Wbqg

CodePudding user response:

If it's a Timestamp field, cast it to Timestamp. If you need that as a DateTime, use a .toDate on that. Don't process it through a string... completely unnecessary.

  • Related