2020-07-08 13:13:24 +00:00
|
|
|
import 'package:geosmart/model/setting.dart';
|
2019-12-16 00:18:09 +00:00
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
|
2020-07-08 13:13:24 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2020-07-08 13:13:24 +00:00
|
|
|
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);
|
2020-07-08 13:13:24 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2020-07-08 13:13:24 +00:00
|
|
|
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),
|
2020-01-03 15:13:00 +00:00
|
|
|
sharedPreferences.getString(_id),
|
2020-07-08 13:13:24 +00:00
|
|
|
);
|
2019-12-16 00:18:09 +00:00
|
|
|
}
|
|
|
|
}
|