ente/lib/core/configuration.dart

57 lines
1.3 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";
SharedPreferences preferences;
Future<void> init() async {
preferences = await SharedPreferences.getInstance();
}
String getEndpoint() {
return preferences.getString(endpointKey);
}
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);
}
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);
}
}