Advertisement
Guest User

Untitled

a guest
Nov 25th, 2020
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 0.75 KB | None | 0 0
  1.   Future<void> downloadFile(String name, String uuid) async {
  2.     final _localPath = (await findLocalPath()) + Platform.pathSeparator + 'Download';
  3.     final savedDir = Directory(_localPath);
  4.     bool hasExisted = savedDir.existsSync();
  5.     if (!hasExisted) {
  6.       savedDir.createSync();
  7.     }
  8.     await Dio().download(
  9.       '${url}',
  10.       '$_localPath/$name',
  11.       options: Options(
  12.           method: 'POST',
  13.           headers: <String, dynamic>{'Content-Type': 'application/json'}),
  14.       onReceiveProgress: (count, total) {
  15.         downloadingMessages[uuid] = count / total;
  16.         notifyListeners();
  17.       },
  18.     );
  19.     downloadingMessages.remove(uuid);
  20.     downloadedMessages[uuid] = '$_localPath/$name';
  21.     notifyListeners();
  22.   }
  23.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement