geo-smart-app/lib/service/setting_service.dart
2020-07-29 01:11:47 +07:00

34 lines
1.0 KiB
Dart

import 'package:geosmart/model/setting.dart';
import 'package:shared_preferences/shared_preferences.dart';
class SettingService {
final String _host = "host";
final String _id = "id";
Future<SharedPreferences> getSharedPreferences() async {
return await SharedPreferences.getInstance();
}
Future<SettingModel> setSetting(SettingModel setting) async {
SharedPreferences sharedPreferences = await this.getSharedPreferences();
sharedPreferences.setString(_host, setting.host);
sharedPreferences.setString(_id, setting.id);
return await getSetting();
}
Future<SettingModel> clearSetting() async {
SharedPreferences sharedPreferences = await this.getSharedPreferences();
sharedPreferences.remove(_host);
sharedPreferences.remove(_id);
return await getSetting();
}
Future<SettingModel> getSetting() async {
SharedPreferences sharedPreferences = await this.getSharedPreferences();
return SettingModel(
sharedPreferences.getString(_host),
sharedPreferences.getString(_id),
);
}
}