Files
workavia-mail-front/lib/features/caching/hive_cache_version_client.dart
T
2023-03-10 21:10:36 +07:00

29 lines
943 B
Dart

import 'package:shared_preferences/shared_preferences.dart';
import 'package:tmail_ui_user/features/caching/cache_version_client.dart';
import 'package:tmail_ui_user/main/exceptions/exception_thrower.dart';
class HiveCacheVersionClient extends CacheVersionClient {
final SharedPreferences _sharedPreferences;
final ExceptionThrower _exceptionThrower;
HiveCacheVersionClient(this._sharedPreferences, this._exceptionThrower);
@override
String get versionKey => 'HiveCacheVersion';
@override
Future<int?> getLatestVersion() {
return Future.sync(() {
final latestVersion = _sharedPreferences.getInt(versionKey);
return latestVersion;
}).catchError(_exceptionThrower.throwException);
}
@override
Future<bool> storeVersion(int newVersion) {
return Future.sync(() async {
return await _sharedPreferences.setInt(versionKey, newVersion);
}).catchError(_exceptionThrower.throwException);
}
}