How to use Dart's Difference Method and DateTime using a dynamic date? How to use Dart's Difference Method and DateTime using a dynamic date? dart dart

How to use Dart's Difference Method and DateTime using a dynamic date?


Ok, so from my point of view a good way to do it seems to use shared_preferences. Shared preferences allow to store some key/value pair for the user, it's persistent and you can update it.

Here's the package: https://pub.dartlang.org/packages/shared_preferences

Here's a good article giving you details about it : https://www.didierboelens.com/2018/04/shared-preferences---how-to-save-flutter-application-settings-and-user-preferences-for-later-re-use/

The idea would be to create a function, checking if the key of first_use_date exists.

  • If it does do nothing (or you can actually update it)
  • If not you create it with the date of today.

Of course it's persistent since the app stays installed on the device.

For printing duration I let you check this class : https://docs.flutter.io/flutter/intl/DateFormat-class.html

And especially this method (which is not implemented yet) : https://docs.flutter.io/flutter/intl/DateFormat/formatDurationFrom.html

Hope it's helps !!