Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter: type 'String' is not a subtype of type 'DateTime'

I want to get TimeStamp from mysql & Change it into time ago My TimeStamp is look like:

2021-03-04 06:06:48

And in Flutter:

[{id: 1, caption: first post, useruid: b0zbRHZEKMbGSdNoVSjI0gsxXTX2, time: 2021-03-04 06:06:48,}],

Error type 'String' is not a subtype of type 'DateTime'

Here i call to change my date & time to timeago with the help of this plugin..

ListView(
        children: snapshot.data.map<Widget>((document) {
      Provider.of<PostFunctions>(context, listen: false)
          .showTimeAgo(document['time']);
return My Other Code...
)


I show like this in My Text
' , ${Provider.of<PostFunctions>(context, listen: false).getImageTimePosted.toString()}'

I Change my Date&Time Here

  showTimeAgo(dynamic timedata) {
    print(timedata);

    imageTimePosted = timeago.format(timedata);
    print(' my time posted ***** $imageTimePosted');
    notifyListeners();
  }

enter image description here

like image 441
Radiant Developers Avatar asked Feb 21 '26 19:02

Radiant Developers


1 Answers

You probably need to use DateTime.tryParse() method to convert your String into a DateTime since the package use a DateTime and you're giving a String by doing as follow:

showTimeAgo(document['time']);

Make this change:

showTimeAgo(DateTime.tryParse(document['time']));
like image 96
BLKKKBVSIK Avatar answered Feb 23 '26 11:02

BLKKKBVSIK