geo-smart-app/lib/bloc/setting.dart

40 lines
1.0 KiB
Dart
Raw Permalink Normal View History

2019-12-16 00:18:09 +00:00
import 'package:rxdart/rxdart.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:geo_app/model/setting.dart';
class SettingBloc {
PublishSubject<SettingModel> _subject;
final String _host = "host";
final String _id = "id";
SettingBloc() {
this._subject = PublishSubject<SettingModel>();
}
Future<SharedPreferences> getSharedPreferences() async {
return await SharedPreferences.getInstance();
}
setSetting(SettingModel setting) async {
SharedPreferences sharedPreferences = await this.getSharedPreferences();
sharedPreferences.setString(_host, setting.host);
sharedPreferences.setString(_id, setting.id);
this.getSetting();
}
getSetting() async {
SharedPreferences sharedPreferences = await this.getSharedPreferences();
_subject.sink.add(new SettingModel(
sharedPreferences.getString(_host),
sharedPreferences.getString(_id),
2019-12-16 00:18:09 +00:00
));
}
dispose() {
_subject.close();
}
PublishSubject<SettingModel> get subject => _subject;
}