TF-1810 Move all hive clients to a separate folder

(cherry picked from commit c72e16b576835b7748e20ab3e5cce5e1f505a65f)
This commit is contained in:
dab246
2023-05-09 18:26:44 +07:00
committed by Dat Vu
parent f3429619aa
commit 5b01715dcd
44 changed files with 53 additions and 55 deletions
@@ -0,0 +1,29 @@
import 'package:shared_preferences/shared_preferences.dart';
import 'package:tmail_ui_user/features/caching/clients/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);
}
}