David PHAM-VAN

Use the http package

@@ -14,26 +14,22 @@ @@ -14,26 +14,22 @@
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 16
17 -import 'dart:io';  
18 import 'dart:typed_data'; 17 import 'dart:typed_data';
19 18
20 import 'package:flutter/material.dart'; 19 import 'package:flutter/material.dart';
21 import 'package:flutter/services.dart'; 20 import 'package:flutter/services.dart';
  21 +import 'package:http/http.dart' as http;
22 import 'package:pdf/pdf.dart'; 22 import 'package:pdf/pdf.dart';
23 -import 'package:vector_math/vector_math_64.dart';  
24 import 'package:pdf/widgets.dart' as pw; 23 import 'package:pdf/widgets.dart' as pw;
  24 +import 'package:vector_math/vector_math_64.dart';
25 25
26 final _cache = <String, Uint8List>{}; 26 final _cache = <String, Uint8List>{};
27 27
28 Future<Uint8List> _download(String url) async { 28 Future<Uint8List> _download(String url) async {
29 if (!_cache.containsKey(url)) { 29 if (!_cache.containsKey(url)) {
30 print('Downloading $url'); 30 print('Downloading $url');
31 - final client = HttpClient();  
32 - final request = await client.getUrl(Uri.parse(url));  
33 - final response = await request.close();  
34 - final builder = await response.fold(  
35 - BytesBuilder(), (BytesBuilder b, List<int> d) => b..add(d));  
36 - final List<int> data = builder.takeBytes(); 31 + final response = await http.get(Uri.parse(url));
  32 + final data = response.bodyBytes;
37 _cache[url] = Uint8List.fromList(data); 33 _cache[url] = Uint8List.fromList(data);
38 } 34 }
39 35
@@ -10,6 +10,7 @@ environment: @@ -10,6 +10,7 @@ environment:
10 dependencies: 10 dependencies:
11 flutter: 11 flutter:
12 sdk: flutter 12 sdk: flutter
  13 + http:
13 intl: 14 intl:
14 open_file: 15 open_file:
15 git: 16 git: