Stopwatch사용방법
printDownloadInfo(Future<Uint8List> function) async {
print('다운로드 시작');
var stopWatch = Stopwatch()..start(); //Stopwatch 사용방법
Uint8List downloadFile = await function;
stopWatch.stop();
print('다운로드 끝');
print('=========');
print('소요시간 : ${stopWatch.elapsed}');
saveFile(downloadFile, 'icon.ico');
print('용량 : ${downloadFile.lengthInBytes}bytes');
}
.bodyBytes
Future<Uint8List> downloadImage(String url) async {
Uint8List data;
try {
var response = await http.get(Uri.parse(url));
data = response.bodyBytes;
} catch (e) {
var file = File('lib/12_14/icon.ico');
print('잘못된 요청입니다.');
data = await file.readAsBytes();
}
return data;
}
api가 깨져서 올때
Future<List<Stores>> getStores() async {
var url = Uri.parse('http://104.198.248.76:3000/mask');
var response = await http.get(url);
var responseBytes = utf8.decode(response.bodyBytes); // .bodyBytes를 사용해서 한번 거쳐주면 된다.
var json = jsonDecode(responseBytes);
List<dynamic> stores = json['stores'];
var data = stores.map((e) => Stores.fromJson(e)).toList();
return data;
}