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.
Related
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?
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
I'm working on a project that captures a screenshot of a widget and saves it in gallery.
my problem is there is few save to gallery packages in flutter and I tries almost all of them!
they save images as jpg which adds extra black bars around my widget which I don't want them to be there.
is there any package to save images to gallery in PNG format?
I've found the solution after 2 days of struggling with that.
you should save file as PNG to device path then use image_gallery_saver
package to save it as file
File('$dir/file_name${DateTime.now()}.png').writeAsBytes(pngBytes!);
final result = await ImageGallerySaver.saveFile(imagePath);
You can save image to gallery by using Image_gallery_saver plugin.image_gallery_saver
. For the black bars , you have to make sure that the screenshot is attached to the widget , what you want it image.
await ImageGallerySaver.saveImage(uint8list blob);
I want to show a composed SVG image in flutter and I am currently using the flutter_svg library.
My picture consists of different layers that can be put together using the app's GUI (creating an avatar).
In principle it works very well with a stack of SVGPictures, but when loading, the problem arises that some of the SVGs are displayed a little later than others and the graphics look broken in this short time - for example, the upper body of an avatar is not loaded but the rest of the body -> the avatar has a hole in the middle ...
Is there a way to display a composition from SVGPictures only when all parts are loaded and can be displayed? Ideally, a dummy should also be displayed for this long.
SVGs with a lot of layers will definitely cause a bit of lag while loading, hence if you want to load them all smoothly, you can try preloading SVGs.
final svg = SvgPicture.asset('assets/vector.svg');
final svgAnother = SvgPicture.asset('assets/vector.svg');
#override
Widget build(BuildContext context) {
return Stack(
children:[
svg, // Load preloaded svg smoothly
svgAnother,
],
);
}
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;
}