esysberlin / esys-flutter-share

A Flutter plugin for sharing files & text with other applications.
Apache License 2.0
130 stars 147 forks source link

How to select share multiple image along with videos ? #31

Closed prafgup closed 4 years ago

prafgup commented 5 years ago

Is it possible to share multiple images and videos simultaneously ?

Deepanshu-Rohilla commented 4 years ago

Is the function available in latest package?

pragupnewzera commented 4 years ago

@Deepanshu-Rohilla , no its not available yet but I figured it out.

prafgup commented 4 years ago

@Deepanshu-Rohilla

Here is the solution to share a list of files with different extensions can be any Media Type. The map basically maps the filename with extension to Uint8List bytes of media

downloadFiles(List<Media> mediaList, {String optionalText = ''}) async {
    Map<String, Uint8List> shareMap = {};
    for (var media in mediaList) {
      currentIndex = mediaList.indexOf(media) + 1;
      var request = await HttpClient().getUrl(Uri.parse(media.networkURL));
      var response = await request.close();
     String extension = response.headers.contentType.toString().split('/')[1];
      Uint8List bytes = await consolidateHttpClientResponseBytes(response);
      shareMap[media.createDate.toString().trim() + '.' + extension] = bytes;
    }
    await Share.files(
      optionalText,
      shareMap,
      '*/*',
      text: "Shared via PixShare app",
    );
  }