isFirstRunSince static method
Returns true if this is the first time you call this method since installing the given version (build number) of the app, otherwise false.
In contrast to IsFirstRun.isFirstCall(), this method continues to return true as long as the app keeps running after the first call after installing the app, while IsFirstRun.isFirstCall() returns true only on the first call after installing the app.
Implementation
static Future<bool> isFirstRunSince({required int build}) async {
if (_currentBuild == null) _currentBuild = await _getCurrentBuild();
// If _previousBuild has already been read from the shared preferences,
// do not read it again because it may have change for isFirstCall
// to have the most recent value.
if (_previousBuild == null) {
await _ensureInitialized();
_previousBuild = _db.get(_versionSettingsKey);
if (_previousBuild == null) {
// check in shared preferences for compatibility with older versions (<= 1.1.0)
SharedPreferences prefs = await SharedPreferences.getInstance();
try {
_previousBuild = prefs.getInt(_versionSettingsKey);
} on Exception {
_previousBuild = 0;
}
}
_previousBuild ??= 0;
// Update the database with the current build,
// so isFirstCall can detect the change.
await _db.put(_versionSettingsKey, _currentBuild!);
}
// Return true if the current build is at least the required build,
// and if the previous build was less than the required build.
return _currentBuild! >= build && _previousBuild! < build;
}