pause method
Pause the ongoing foreground download
Use resume to resume the download. It is also safe to use cancel without resuming first.
Note that all running parallel download threads will be allowed to finish their current tile download before pausing.
It is not usually necessary to use the result. Returns null if there is
no ongoing download or the download is already paused or pausing.
Otherwise returns whether the download was paused (false if resume is
called whilst the download is being paused).
Any buffered tiles are not flushed.
By default, only one download is allowed at any one time, across all stores.
However, if necessary, multiple can be started by setting methods'
instanceId argument to a unique value on methods. Whatever object
instanceId is, it must have a valid and useful equality and hashCode
implementation, as it is used as the key in a Map. Note that this unique
value must be known and remembered to control the state of the download.
Note that instances are shared across all stores.
Warning
Starting multiple simultaneous downloads may lead to a noticeable performance loss. Ensure you thoroughly test and profile your application.
Implementation
Future<bool?> pause({Object instanceId = 0}) {
final instance = DownloadInstance.get(instanceId);
if (instance == null ||
instance.isPaused ||
!instance.pausingCompleter.isCompleted ||
instance.requestPause == null) {
return SynchronousFuture(null);
}
instance
..pausingCompleter = Completer()
..resumingAfterPause = Completer();
instance.requestPause!().then((_) {
instance.pausingCompleter.complete(true);
if (!instance.resumingAfterPause!.isCompleted) instance.isPaused = true;
instance.resumingAfterPause = null;
});
return Future.any(
[instance.resumingAfterPause!.future, instance.pausingCompleter.future],
);
}