Skip to content
Snippets Groups Projects
Select Git revision
  • c4c1da270171f18f18525a52e2489fe0feaa4395
  • master default protected
  • 19-improve-app-metadata
  • Release_0.8.1_34 protected
  • Release_0.8.0_33 protected
  • Release_0.7.2_32 protected
  • Release_0.7.1_31 protected
  • Release_0.7.0_30 protected
  • Release_0.6.0_29 protected
  • Release_0.5.0_28 protected
  • Release_0.4.0_27 protected
  • Release_0.3.2_26 protected
  • Release_0.3.1_25 protected
  • Release_0.3.0_24 protected
  • Release_0.2.1_23 protected
  • Release_0.2.0_22 protected
  • Release_0.1.2_21 protected
  • Release_0.1.1_20 protected
  • Release_0.1.0_19 protected
  • Release_0.0.18_18 protected
  • Release_0.0.17_17 protected
  • Release_0.0.16_16 protected
  • Release_0.0.15_15 protected
23 results

data.dart

Blame
  • 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();
      }
    }