How can I solve this Jiffy constructor error?

192 views Asked by At

I am not sure the best constructor to add in this use case. Still trying to figure out flutter so I got stuck here while trying to build an app.

I have tried the different constructors like "jiffy.datetime" "jiffy.parsejiffy" etc but they seem not to have solved the issue but keeps returning the same error.enter image description here

Please help

1

There are 1 answers

0
Jama Mohamed On

Based from you code, you seem to use Jiffy incorrectly. As of version 6.0.0 Jiffy does not allow to create its instance soley by calling the constructor

You have to use factory methods to create one

So below I have re-written your code to solve the issue you are having

// This looks great 
Jiffy createAt = Jiffy.parseFromDateTime(widget.datetime);

// On line 277
// Rather than
final now = Datetime.now() // remove this
// Use Jiffy
final now = Jiffy.now() // Now you have a Jiffy instance

// If you want to get a Datetime from a Jiffy, just write
now.datetime; // This will return a Datetime object/instance


// On line 279
// Rather than creating another instance of Jiffy
Jiffy.parseFromJiffy(createAt).isSame(now, Units.day) // remove this
// Use the createdAt since it a Jiffy instance itself
createdAt.isSame(now, Units.day) // replace it with this

// And one additional thing, the `isSame` methods takes in a Jiffy 
// object/instance, not a Datetime object


// On line 281 - 282
// Rather than
Jiffy(createdAt).isSame(now.subtract(const Duration(days: 1), Units.day))
// Replace it with
createdAt.isSame(now.subtract(days: 1), Units.day))


// On line 284 - 286
// Rather than
Jiffy(createAt).isAfter(now.subtract(const Duration(days: 7), Units.day))
// Replace it with
createdAt.isAfter(now.subtract(days: 7), Units.day))
// or you can use `week: 1` also that Jiffy supports
createdAt.isAfter(now.subtract(weeks: 1), Units.day))


// On line 290 - 291
// Rather than 
Jiffy(createdAt).isAfter(Jiffy(now).subtract(years: 1), Units.day))
// Replace it with
createdAt.isAfter(now.subtract(years: 1), Units.day))

Hope this helps on how to use Jiffy, if you have additional questions, please feel free to ask