recordLaunch method

Future<void> recordLaunch()

Records an app launch and initialises the install timestamp on first run.

Implementation

Future<void> recordLaunch() async {
  final prefs = SharedPreferencesAsync();
  final now = DateTime.now().millisecondsSinceEpoch;

  final firstLaunch = await prefs.getInt(_kFirstLaunchKey);
  if (firstLaunch == null) {
    await prefs.setInt(_kFirstLaunchKey, now);
  }

  final count = (await prefs.getInt(_kLaunchCountKey)) ?? 0;
  await prefs.setInt(_kLaunchCountKey, count + 1);
}