downloadUpdate method

Future<void> downloadUpdate()

Implementation

Future<void> downloadUpdate() async {
  if (_folderUrl == null) {
    throw Exception("Folder URL is not set");
  }

  if (_changedFiles == null) {
    throw Exception("Changed files are not set");
  }

  _isDownloading = true;
  _isDownloaded = false;
  _downloadProgress = 0;
  _downloadedSize = 0;
  _stagingPath = null;
  notifyListeners();

  final stream = await _plugin.updateApp(
    remoteUpdateFolder: _folderUrl!,
    changedFiles: _changedFiles ?? [],
  );

  try {
    await for (final event in stream) {
      _updateProgress = event;
      _stagingPath = event.stagingDirectory ?? _stagingPath;
      _isDownloading = true;
      _isDownloaded = false;
      _downloadProgress = event.fraction;
      _downloadedSize = event.receivedBytes;
      notifyListeners();
    }

    _isDownloading = false;
    _downloadProgress = 1.0;
    _downloadedSize = _downloadSize;
    _isDownloaded = true;
    notifyListeners();
  } catch (_) {
    _isDownloading = false;
    _isDownloaded = false;
    notifyListeners();
    rethrow;
  }
}