commit method

Future<bool> commit()

Implementation

Future<bool> commit() async {
  var results = [];

  for (var entry in pref.entries) {
    bool? result;

    var args = Map();
    args[_PARAM_NAME] = _self._name;
    args[_PARAM_MODE] = _self._mode;
    args[_PARAM_KEY] = entry.key;
    args[_PARAM_VALUE] = entry.value;
    args[_PARAM_USE_DEVICE_PROTECTED_STORAGE] =
        _self.useDeviceProtectedStorage;

    if (entry.value is int) {
      result = await invokeMethod<bool>(_PUT_INT, args);
    } else if (entry.value is double) {
      result = await invokeMethod(_PUT_FLOAT, args);
    } else if (entry.value is String) {
      result = await invokeMethod(_PUT_STRING, args);
    } else if (entry.value is bool) {
      result = await invokeMethod(_PUT_BOOLEAN, args);
    }

    if (result != null) {
      results.add(result);
      if (result) _self._preference[entry.key] = entry.value;
    }
  }

  return !results.contains(false);
}