startForeground method

Stream<DownloadProgress> startForeground({
  1. required DownloadableRegion region,
  2. FMTCTileProviderSettings? tileProviderSettings,
  3. bool disableRecovery = false,
})

Download a specified DownloadableRegion in the foreground

To check the number of tiles that need to be downloaded before using this function, use check.

Unless otherwise specified, also starts a recovery session.

Streams a DownloadProgress object containing lots of handy information about the download's progression status; unless the pre-download checks fail, in which case the stream's .isEmpty will be true and no new events will be emitted. If you get messages about 'Bad State' after dealing with the checks, just add .asBroadcastStream() on the end of startForeground.

Implementation

Stream<DownloadProgress> startForeground({
  required DownloadableRegion region,
  FMTCTileProviderSettings? tileProviderSettings,
  bool disableRecovery = false,
}) async* {
  _recoveryId = hashValues(
        region,
        tileProviderSettings,
        _storeDirectory.getTileProvider(tileProviderSettings),
      ) *
      DateTime.now().millisecondsSinceEpoch;

  if (!disableRecovery) {
    await _storeDirectory.rootDirectory.recovery.start(
      id: _recoveryId!,
      storeName: _storeDirectory.storeName,
      region: region,
      storeDirectory: _storeDirectory,
    );
  }

  _queue = Queue(parallel: region.parallelThreads);
  _streamController = StreamController();

  yield* _startDownload(
    tileProviderSettings: tileProviderSettings,
    region: region,
    tiles: await _generateTilesComputer(region),
  );
}