geo-smart-app/lib/bloc/setting.dart
Supan Adit Pratama 3ead80b465 Migrate to Android X
Update some Dependencies
Logo Added
Start and Stop Tracking Button
Optimize Code
Stable Version
2020-01-03 22:13:00 +07:00

40 lines
1.0 KiB
Dart

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),
));
}
dispose() {
_subject.close();
}
PublishSubject<SettingModel> get subject => _subject;
}