Aoi-hosizora / flutter_ahlib

A personal flutter library, contains some useful widgets and utils.
MIT License
3 stars 0 forks source link

Add header for http.head in LocalOrNetworkImageProvider #2

Closed Aoi-hosizora closed 3 years ago

Aoi-hosizora commented 3 years ago

The http.head header should contain the headers parameter.

      int totalSize;
      http.head(url, headers: {
        'Accept': '*/*',
        'Accept-Encoding': '',
      }).then((data) {
        totalSize = int.tryParse(data.headers['content-length']);
      });
Aoi-hosizora commented 3 years ago

Done

var h = (headers ?? {})..['Accept-Encoding'] = '';
int totalSize;
http.head(url, headers: {
  'Accept': '*/*',
  ...h,
}).then((data) {
  totalSize = int.tryParse(data.headers['content-length']);
}).catchError((_) {});