download method Null safety
Download from sync IP
Implementation
void download() async {
// Get path for distro filesystem
String? syncIP = prefs.getString('SyncIP');
if (syncIP == null) {
statusMsg('syncipnotset-text'.i18n(), loading: false);
return;
}
statusMsg('${'shuttingdownwsl-text'.i18n()}...', loading: true);
// Shutdown WSL
await WSLApi().shutdown();
statusMsg('${'connectingtoip-text'.i18n()}: "$syncIP"...', loading: true);
Dio().download(
'http://$syncIP:59132/ext4.vhdx', '$distroLocation\\ext4.vhdx',
onReceiveProgress: (received, total) {
String rec = (received / 1024 / 1024).toStringAsFixed(2);
String tot = (total / 1024 / 1024).toStringAsFixed(2);
statusMsg('${'downloading-text'.i18n()} $distroName, $rec MB / $tot MB',
loading: true);
if (received == total) {
statusMsg('${'downloaded-text'.i18n()} $distroName');
}
}).catchError((e) {
statusMsg('${'errordownloading-text'.i18n()} $distroName',
loading: false);
});
}