geo-smart-app/lib/service/setting_service.dart

34 lines
1.0 KiB
Dart
Raw Permalink Normal View History

import 'package:geosmart/model/setting.dart';
2019-12-16 00:18:09 +00:00
import 'package:shared_preferences/shared_preferences.dart';
class SettingService {
2019-12-16 00:18:09 +00:00
final String _host = "host";
final String _id = "id";
Future<SharedPreferences> getSharedPreferences() async {
return await SharedPreferences.getInstance();
}
Future<SettingModel> setSetting(SettingModel setting) async {
2019-12-16 00:18:09 +00:00
SharedPreferences sharedPreferences = await this.getSharedPreferences();
sharedPreferences.setString(_host, setting.host);
sharedPreferences.setString(_id, setting.id);
return await getSetting();
2019-12-16 00:18:09 +00:00
}
2020-07-28 18:11:47 +00:00
Future<SettingModel> clearSetting() async {
SharedPreferences sharedPreferences = await this.getSharedPreferences();
sharedPreferences.remove(_host);
sharedPreferences.remove(_id);
return await getSetting();
}
Future<SettingModel> getSetting() async {
2019-12-16 00:18:09 +00:00
SharedPreferences sharedPreferences = await this.getSharedPreferences();
2020-07-28 18:11:47 +00:00
return SettingModel(
2019-12-16 00:18:09 +00:00
sharedPreferences.getString(_host),
sharedPreferences.getString(_id),
);
2019-12-16 00:18:09 +00:00
}
}