downloadFile method
Future
downloadFile(
- dynamic filename,
- dynamic context,
- dynamic needRemove,
- dynamic subject,
)
Implementation
Future downloadFile(filename, context, needRemove, subject) async {
myLogAll('downloadFile');
dynamic filePath = '';
try {
dynamic myUrl =
'http://${MyConfig.URL.name}/${MyConfig.DOWNLOAD.name}?filename=$filename&needRemove=$needRemove';
http.Response response = (await httpClient.get(Uri.parse(myUrl)));
if (response.statusCode == 200) {
var bytes = response.bodyBytes;
Directory dir = await getTemporaryDirectory();
dynamic tempPath = dir.path;
filePath = '$tempPath/$filename';
File file = File(filePath);
await file.writeAsBytes(bytes);
navigatorPush(context, PDFScreen({gPath: filePath, gSubject: subject}));
} else {
showMsg(context, 'Error code: ${response.statusCode}', null);
}
} catch (ex) {
showMsg(context, ex, null);
}
}