How to share image + text both to WhatsApp from flutter app - flutter

I try to use this package
share_plus
from flutter to make user can share image + text with other apps (WhatsApp). It works fine on Android, but the problem is in IOS I can't share image and text same in one time. I searched for a long time but could not find a solution to this problem.
Code:
Future ShareImage()async{
var urls='https://upload.wikimedia.org/wikipedia/commons/thumb/b/b6/Image_created_with_a_mobile_phone.png/1200px-Image_created_with_a_mobile_phone.png';
final url=Uri.parse(urls);
final res =await http.get(url);
final bytes =res.bodyBytes;
final temp = await getTemporaryDirectory();
final path ='${temp.path}/imageToShare.jpg';
File(path).writeAsBytesSync(bytes);
Share.shareFiles([path],text:'Great picture'); }
Anyone have a way to solve this problem?

I think you need these packages for your need according.
whatsapp_share2: https://pub.dev/packages/whatsapp_share2
whatsapp_share: https://pub.dev/packages/whatsapp_share
akvelon_flutter_share_plugin:
https://pub.dev/packages/akvelon_flutter_share_plugin
flutter_share: https://pub.dev/packages/flutter_share
More package available at https://pub.dev

Related

Flutter screenshot of platform view

I have an app that shows a platform view (a map widget) with other widget on top and I need to take a screenshot of the map but I don't know how and the best that I got is a blank screen.
The desired result is a screenshot of the map only but a screenshot of everything on the screen, as the phonescreenshot does, is acceptable too.
I tried with the package Screenshot, Take Screenshot and Native Screenshot, plus, I tried wit the RenderRepaintBoundary technique
RenderRepaintBoundary boundary = scr.currentContext?.findRenderObject() as RenderRepaintBoundary;
ui.Image image = await boundary.toImage();
ByteData? byteData = await image.toByteData(format: ui.ImageByteFormat.png);
var img = byteData?.buffer.asUint8List();
And I even went over the first page on Google search!
Unfortunately the best that I obtained is a blank screenshot and these two errors:
[ERROR:flutter/flow/layers/platform_view_layer.cc(20)] Trying to embed a platform view but the PrerollContext does not support embedding
[ERROR:flutter/flow/layers/platform_view_layer.cc(35)] Trying to embed a platform view but the PaintContext does not support embedding
Can someone help me?
Ps. The map widget could be a Google Map or not, so "Use googleMapController.takeSnapshot()" is not an available answer.

Flutter image_picker pre-select images

I'm using the flutter image_picker plugin. I can use
final ImagePicker picker = ImagePicker();
final List<XFile> images = await picker.pickMultiImage(imageQuality: 60);
After a user has picked multiple images for their post and exit out, they can always go back and select more images - in which case I want the images already selected to be "pre-selected". The API has no way to do this I think, so I'm wondering if there is a similar/reliable plugin that can do this and is well supported.
I've googled and found multiple plugins for image picking - and none of them seem to support this feature. I'm tempted to try and roll my own but would prefer to find a plugin if one exists. Any recommendations I could try?

Flutter Web Save Image

I was working on a flutter web app where I need to save an image created using canvas.I tried FileSaver.js library but it wasn't successful for me.
Index.html main.dart
I created simple package image_downloader_web that can easily download image from web.
final WebImageDownloader _webImageDownloader = WebImageDownloader();
const _url = "https://picsum.photos/200";
Future<void> _downloadImage() async {
await _webImageDownloader.downloadImageFromWeb(_url);
}

Image_picker, how to use ImageSource Camera and Gallery in one function

I have implemented the possibility to take picture but what I want is to offer the user both options just like in other apps (e.g. WhatsApp) where you can choice between the Camera or Gallery.
I looked on the Image_picker documentation but didn't find anything. Am I missing something or there is no way to achieve it with this plugin?
I supposed you can create multiple different widgets (buttons) that access the different source of images? Not sure if it's the best way though.
Future getImage(ImageSource imageSource) async {
// ImageSource.camera or ImageSource.gallery
File image = await ImagePicker.pickImage(source: imageSource);
return image;
}

Bug with image picker with flutter on ImageSource.Gallery

Info:
Package: image_picker plugin for flutter, version 0.6.3+1
Android build only, no IOS
Problem:
This is my method to pick an image:
Future<void> pickImage(ImageSource source) async {
File selected = await ImagePicker.pickImage(source: source);
print(selected?.path);
imageFilePath = selected?.path ?? imageFilePath;
}
=> When using ImageSource.gallery, when choosing a picture which is not in cache, 'selected.path' prints null. When selecting a picture which is in cache, it does retrieve it, 'selected.path' prints:
/data/user/0/be.etnic.parrainage_mcf/cache/image_picker2517179621202627006.jpg
Anyone knows what causes this problem and how I can solve it?
Sidenotes:
I can also pick an image by making a picture directly with ImageSource.camera, this doesn't give me any problems.
I'm not 100% sure that the selected pictures that return null
are not in cache, but the pictures that do return correctly from
choosing from the ImageSource.gallery all come from that
cache-folder
I don't have any permissions set in my AndroidManifest.xml
(other than Internet permission)
Based on this link https://github.com/flutter/flutter/issues/41459#issuecomment-563986851, following should solve the problem:
android:requestLegacyExternalStorage="true"