ente/lib/core/configuration.dart
2020-05-06 19:21:25 +05:30

57 lines
1.3 KiB
Dart

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";
SharedPreferences _preferences;
Future<void> init() async {
_preferences = await SharedPreferences.getInstance();
}
String getEndpoint() {
return _preferences.getString(_endpointKey);
}
String getHttpEndpoint() {
if (getEndpoint() == null) {
return "";
}
return "http://" + getEndpoint() + ":8080";
}
void setEndpoint(String endpoint) async {
await _preferences.setString(_endpointKey, endpoint);
}
String getToken() {
return _preferences.getString(_tokenKey);
}
void setToken(String token) async {
await _preferences.setString(_tokenKey, token);
}
String getUsername() {
return _preferences.getString(_usernameKey);
}
void setUsername(String username) async {
await _preferences.setString(_usernameKey, username);
}
String getPassword() {
return _preferences.getString(_passwordKey);
}
void setPassword(String password) async {
await _preferences.setString(_passwordKey, password);
}
}