ModelDownloader constructor

ModelDownloader({
  1. Uri? baseUrl,
  2. HttpClient? httpClient,
  3. Duration connectionTimeout = const Duration(seconds: 30),
  4. Duration stallTimeout = const Duration(seconds: 60),
})

Creates a downloader.

baseUrl lets you point at a mirror or an internal copy; it must end with a slash for the file name to resolve against it. Pass httpClient to reuse a client you already configured — proxies, certificates, timeouts; in that case closing it stays your responsibility, and connectionTimeout is left to whatever you set on it.

connectionTimeout bounds reaching the server and getting an answer out of it, stallTimeout the longest silence allowed in the middle of the body. Without them a server that accepts the connection and then says nothing holds the caller forever — and this is the call an app makes while starting up.

Implementation

ModelDownloader({
  Uri? baseUrl,
  HttpClient? httpClient,
  this.connectionTimeout = const Duration(seconds: 30),
  this.stallTimeout = const Duration(seconds: 60),
}) : baseUrl = baseUrl ?? defaultBaseUrl,
     _httpClient = httpClient ?? HttpClient(),
     _ownsClient = httpClient == null {
  if (_ownsClient) {
    _httpClient.connectionTimeout = connectionTimeout;
  }
}