Home > Back-end >  Is it possible to send image or files through url_launcher in flutter
Is it possible to send image or files through url_launcher in flutter

Time:01-03

Text can be send through url_launcher package but is it supports images or files to send it to other apps install in device?

CodePudding user response:

No, you can't use url_launcher package to send file/images. However, this can be done with share_plus plugin. It supports files/images/texts etc, you can read more about it in documentation.

CodePudding user response:

                final _url = "https://source.unsplash.com/random?sig=1";
                final response = await http.get(Uri.parse(_url));

                // Get the image name
                final imageName = path.basename(_url);
                // Get the document directory path
                final appDir = await 
                pathProvider.getApplicationDocumentsDirectory();

                // This is the saved image path
                // You can use it to display the saved image later.
                final localPath = path.join(appDir.path, imageName);

                // Downloading
                final imageFile = File(localPath);
                await imageFile.writeAsBytes(response.bodyBytes);
                // String img = base64Encode(imageFile.readAsBytesSync());
                // String name = imageFile.path.split("/").last;
                // Future.delayed(Duration(seconds: 3), () async {
                await Share.shareFiles([imageFile.path], text: 'Great picture');
                // });
  • Related