configuration.dart 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import 'package:shared_preferences/shared_preferences.dart';
  2. class Configuration {
  3. Configuration._privateConstructor();
  4. static final Configuration instance = Configuration._privateConstructor();
  5. static const endpointKey = "endpoint_7";
  6. static const tokenKey = "token";
  7. static const usernameKey = "username";
  8. static const passwordKey = "password";
  9. SharedPreferences preferences;
  10. Future<void> init() async {
  11. preferences = await SharedPreferences.getInstance();
  12. }
  13. String getEndpoint() {
  14. return preferences.getString(endpointKey);
  15. }
  16. String getHttpEndpoint() {
  17. if (getEndpoint() == null) {
  18. return "";
  19. }
  20. return "http://" + getEndpoint() + ":8080";
  21. }
  22. void setEndpoint(String endpoint) async {
  23. await preferences.setString(endpointKey, endpoint);
  24. }
  25. String getToken() {
  26. return preferences.getString(tokenKey);
  27. }
  28. void setToken(String token) async {
  29. await preferences.setString(tokenKey, token);
  30. }
  31. String getUsername() {
  32. return preferences.getString(usernameKey);
  33. }
  34. void setUsername(String username) async {
  35. await preferences.setString(usernameKey, username);
  36. }
  37. String getPassword() {
  38. return preferences.getString(passwordKey);
  39. }
  40. void setPassword(String password) async {
  41. await preferences.setString(passwordKey, password);
  42. }
  43. }