ente/lib/core/configuration.dart

61 lines
1.4 KiB
Dart
Raw Normal View History

2020-04-30 15:09:41 +00:00
import 'package:shared_preferences/shared_preferences.dart';
class Configuration {
Configuration._privateConstructor();
static final Configuration instance = Configuration._privateConstructor();
static const _endpointKey = "endpoint_7";
static const _tokenKey = "token";
static const _usernameKey = "username";
static const _passwordKey = "password";
2020-04-30 15:09:41 +00:00
SharedPreferences _preferences;
2020-04-30 15:09:41 +00:00
Future<void> init() async {
_preferences = await SharedPreferences.getInstance();
2020-04-30 15:09:41 +00:00
}
String getEndpoint() {
return _preferences.getString(_endpointKey);
2020-04-30 15:09:41 +00:00
}
2020-04-30 15:18:26 +00:00
String getHttpEndpoint() {
if (getEndpoint() == null) {
return "";
}
2020-04-30 15:18:26 +00:00
return "http://" + getEndpoint() + ":8080";
}
2020-04-30 15:09:41 +00:00
void setEndpoint(String endpoint) async {
await _preferences.setString(_endpointKey, endpoint);
2020-04-30 15:09:41 +00:00
}
String getToken() {
return _preferences.getString(_tokenKey);
2020-04-30 15:09:41 +00:00
}
void setToken(String token) async {
await _preferences.setString(_tokenKey, token);
2020-04-30 15:09:41 +00:00
}
String getUsername() {
return _preferences.getString(_usernameKey);
2020-04-30 15:09:41 +00:00
}
void setUsername(String username) async {
await _preferences.setString(_usernameKey, username);
2020-04-30 15:09:41 +00:00
}
String getPassword() {
return _preferences.getString(_passwordKey);
2020-04-30 15:09:41 +00:00
}
void setPassword(String password) async {
await _preferences.setString(_passwordKey, password);
2020-04-30 15:09:41 +00:00
}
bool hasConfiguredAccount() {
return getEndpoint() != null && getToken() != null;
}
2020-04-30 15:09:41 +00:00
}