isFirstCallSince static method

Future<bool> isFirstCallSince({
  1. required int build,
})

Returns true if this is the first time this function has been called since installing the given version (build number) of the app, otherwise false.

In contrast to IsFirstRun.isFirstRun(), this method only returns true on the first call after installing the app, while IsFirstRun.isFirstRun() continues to return true as long as the app is running after calling it the first time after installing it.

Implementation

static Future<bool> isFirstCallSince({required int build}) async {
  if (_currentBuild == null) _currentBuild = await _getCurrentBuild();
  // Read the last build saved to the database:
  // If no function has been called since the last update,
  // it will be the previous version.
  // Otherwise it will already be the current version,
  // thus this function will return false.
  await _ensureInitialized();
  int? lastBuild = _db.get(_versionSettingsKey);
  if (lastBuild == null) {
    // check in shared preferences for compatibility with older versions (<= 1.1.0)
    SharedPreferences prefs = await SharedPreferences.getInstance();
    try {
      lastBuild = prefs.getInt(_versionSettingsKey);
    } on Exception {
      lastBuild = 0;
    }
  }
  lastBuild ??= 0;
  await _db.put(_versionSettingsKey, _currentBuild!);

  // Return true if the current build is at least the required build,
  // and if the last stored build is less than the required build.
  return _currentBuild! >= build && lastBuild < build;
}