Select Git revision
data.dart 1.28 KiB
import 'package:flutter/foundation.dart';
import 'package:shared_preferences/shared_preferences.dart';
class Data extends ChangeNotifier {
// Application settings
String _apiHost = '';
String _apiStatus = '';
String defaultApiHost = '127.0.0.1';
getParameterValue(String parameterCode) {
switch (parameterCode) {
case 'apiHost':
{
return _apiHost;
}
}
}
setParameterValue(String parameterCode, String parameterValue) async {
print('set parameter "' + parameterCode + '" to value "' + parameterValue + '"');
switch (parameterCode) {
case 'apiHost':
{
updateApiHost(parameterValue);
}
break;
}
final prefs = await SharedPreferences.getInstance();
prefs.setString(parameterCode, parameterValue);
}
void initParametersValues() async {
final prefs = await SharedPreferences.getInstance();
setParameterValue('apiHost', prefs.getString('apiHost') ?? this.defaultApiHost);
}
String get apiHost => _apiHost;
void updateApiHost(String apiHost) {
_apiHost = apiHost;
notifyListeners();
}
String get apiStatus => _apiStatus;
void updateApiStatus(String apiStatus) {
print('new API status: ' + apiStatus);
_apiStatus = apiStatus;
notifyListeners();
}
}