runable
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import 'package:hive_ce/hive.dart';
|
||||
import '../models/app_settings_model.dart';
|
||||
import '../../../../core/constants/storage_constants.dart';
|
||||
import '../../../../core/constants/app_constants.dart';
|
||||
|
||||
/// Settings local data source using Hive
|
||||
abstract class SettingsLocalDataSource {
|
||||
Future<AppSettingsModel> getSettings();
|
||||
Future<void> updateSettings(AppSettingsModel settings);
|
||||
}
|
||||
|
||||
class SettingsLocalDataSourceImpl implements SettingsLocalDataSource {
|
||||
final Box<AppSettingsModel> box;
|
||||
|
||||
SettingsLocalDataSourceImpl(this.box);
|
||||
|
||||
@override
|
||||
Future<AppSettingsModel> getSettings() async {
|
||||
var settings = box.get(StorageConstants.settingsKey);
|
||||
|
||||
// Return default settings if not found
|
||||
if (settings == null) {
|
||||
settings = AppSettingsModel(
|
||||
themeModeString: 'system',
|
||||
language: AppConstants.defaultLanguage,
|
||||
currency: AppConstants.defaultCurrency,
|
||||
taxRate: AppConstants.defaultTaxRate,
|
||||
storeName: AppConstants.appName,
|
||||
enableSync: true,
|
||||
);
|
||||
await box.put(StorageConstants.settingsKey, settings);
|
||||
}
|
||||
|
||||
return settings;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> updateSettings(AppSettingsModel settings) async {
|
||||
await box.put(StorageConstants.settingsKey, settings);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user