Picked gallery Image path flutter - flutter

I'm working on a app where I would like to get the local path of the selected/picked image from my mobile gallery instead of image_picker path. I have used image _picker to pick an image from the gallery. When I print the path of the selected image it showing something like this /data/user/0/coffy.testapp/cache/image_picker5380473371212438250.jpg instead I need a path of the image like /data/emulated/downloads/021545.png (The path I can see in my mobile when I click the image details of a particular image);

You need to access local storage and select from there.
https://flutter.dev/docs/cookbook/persistence/reading-writing-files
https://pub.dev/packages/path_provider

Related

Path Provider Using and Asset Problems

I want to add an image that I added to my application from the phone's gallery to the list and call it with Image.asset as a String value.
I managed to get the image with ImagePicker. Unfortunately, there is no next. I don't know exactly how to do this.
In short: I will select an image from gallery with ImagePicker and replace it with "Image.file"
I will do it by converting it to String value with Image.asset.
You have to use image.file or image.memory to load an image from ImagePicker.
image.asset is for images that already exist within your app.

how to save uint8list to gallery as png

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);

how to use an specific image icon in flutter local notification?

the application's logo is PNG,so in android lollipop this icon convert to be a white square. so i need to use another image in JPG format for flutter local notification.
i have two questions:
first:
where should i put this image?
second:
how could i access this image?
the code is :
const AndroidInitializationSettings initializationSettingsAndroid =
AndroidInitializationSettings('#mipmap/ic_launcher');
You should create a new image with size 48x48. You can have it as png as well as long as there is transparency and image itself is white.
Let's call this file ic_notification.png
Navigate to your project root directory. You will find android directory. Expand it see following directory in nested order
app
src
main
res
mipmap
if you don't see mipmap folder or different versions of mipmap folder, like mipmap-xxxdpi or mipmap-hdpi etc, create mipmap folder there and put your icon file in that folder.
On flutter side, replace AndroidInitializationSettings('#mipmap/ic_launcher'); with AndroidInitializationSettings('#mipmap/ic_notification'); (without .png)
You should have different icon for app launcher and notification as they serve different purpose.

Is there a way to specify the file name in advance for the picture taken with the flutter camera plugin?

Hi I am using the flutter camera plugin and it works fine, the main issue I am having is that I can't find a way to tell the plugin the image file name when taking the picturee, in android using Kotlin this would be something like:
photoUri = FileProvider.getUriForFile(requireActivity(), "io.awesomedomain", photoFile) // build uri on the app storage space and specific file name -> photoFile.
captureImageIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri) // define the pic name before picture is actually taken by the camera.
startActivityForResult(captureImageIntent, REQUEST_PHOTO) // start the camera
I am currently just renaming the picture file name after the picture XFile returns from the flutter camera plugin but this doesn't feel optimal so I am wondering if I am missing something. Is it possible to specify the file name in advance to the flutter camera plugin?
I am currently using the latest available version at the moment: camera: ^0.7.0+2
OK, it looks like I had a misunderstanding of the Camera plugin, I noticed that the returned XFile places the picture in the cache directory and actually provides a method to save the picture to a more definitive storage xfile.saveTo so I did:
var appDir = appDocDirectory.parent.path; // get app directory
file.saveTo('$appDir${Platform.pathSeparator}files${Platform.pathSeparator}${weightPicture.pictureFileName}');
So the picture is properly saved under $myAppDir/files/picName.jpg where the files is a directory I configured to have permission to write to and the picName is defined by the application as I wanted.

Old cached image displays after clear local cache, want to display newly downloaded image from network

In my app I download an image from the network then save this image in local cache storage with a specific name such as test.jpeg, then I display the test.jpeg image in Android device.
If I clear local cache for the app in android settings, then again download new image from network and save the new image with the same name (test.jpeg). Then I display the image, I expect the new image should be displayed but it displayed the old image.
After killing the app and running it again then it displays the new image.
To download and save the image I use Dio library.
Here is sample code of download and save to local directory
Dio client;
String imageSavePath =
path.join((await getTemporaryDirectory()).path, “test.jpeg”);
await client.download(url, imageSavePath);
So, how can I display newly downloaded image without closing the app.
Please check below link https://api.flutter.dev/flutter/painting/imageCache.html
import 'package:flutter/services.dart';
imageCache.clear();
It might works for you.