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

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.

Related

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

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.

Picked gallery Image path 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

Flutter | how to add custom Icons in Mapbox's markers/symbol

I was wondering how one could use his own icons in a Flutter-Mapbox plugins' marker?
There's no default marker icon (no provided icon - no marker),
and there's not enough documentation on how to use a custom image.
adding a symbol (marker) is as follows:
mapController.addSymbol(
SymbolOptions(
geometry:LatLng(0.0, 0.0), // location is 0.0 on purpose for this example
iconImage: "pin"
)
);
whereas the IconImage, a String, is the field which should contain the data about the icon (obviously), but the given example repository doesn't clarify the needed parameters (url, path etc.).
Providing a path to the assets doesn't work (unlike other widgets). In the example, they provide the IconImage field the value airport-15, and when running the app, it actually works, but I can't seem to find the resources' location (it's not in #drawables or my assets folder, or any other place in the project)
You have to create a custom style on using MapBox Studio.
Create a new dataset if not already exist
Create tileset
Create new style & select customize basic template
Create new layer, give it a name for example my_sym and add newly created datasource
Then click on type & change it to symbol
Now click on my_sym two times. (first one will close the option menu & second one will open a new menu with symbol properties
Click on icon tab & select new icon. You can also upload your own svg icon.
Click on publish
Click on share it will show you the urls.
Copy the type of url & set styleString property.
For more info follow steps here
https://docs.mapbox.com/help/tutorials/add-points-pt-1/
API reference:
https://docs.mapbox.com/mapbox-gl-js/api/
As of release 0.0.5 it will be possible to load custom icon images for your markers. The idea is to add the icon image to your assets folder (for example: assets/symbols/custom-icon.png). If you specify this image as an asset in your pubspec.yaml and set the iconImage in the SymbolOptions to this path it will be loaded automatically.
Regarding the airport-15, this is an icon provided by the Android implementation of the plugin. It is part of the Maki Icons used in Mapbox. Because these icons are part of the Android implementation you will not find as a Flutter asset or an Android resource of the example app.

notification icon dones't show in flutter andriod app local_notification_flutter

I'm new in flutter so please don't kill me if my question is easy.
notification icon doesn't show like this
I put in this path
\android\app\src\main\res\drawable
here is my code for icon:
final settingsAndroid = AndroidInitializationSettings('app_icon');
final settingsIOS = IOSInitializationSettings(onDidReceiveLocalNotification: (id, title, body, payload) => onSelectNotification(payload));
final settingsIOSgeneral = IOSInitializationSettings(onDidReceiveLocalNotification: (id, title, body, payload) => onSelectNotificationgeneral(payload));
notifications.initialize(InitializationSettings(settingsAndroid, settingsIOS), onSelectNotification: onSelectNotification);
Can Any one help me please how can I preview my icon in notification ?
I did the following and it worked for me:
Create a transparent and white notification icon (you can use the following tool: AndroidAssetStudio )
Download the zip folder, unzip and you'll see it contains a res folder with different drawable folders. Copy and paste the contents of the res folder in "android\app\src\main\res" path
Then open the AndroidManifest.xml file and add the following lines to it:
ic_stat_calendar_today is the name of my notification icon. And each of the drawable folders that have been pasted contain a different size of icon with the same name.
If you want to change the color of the icon then check the above image. Add the metadata tag after the notification icon tag
Go to "android\app\src\main\res\values" and add a colors.xml file
<color name="colorAccent">#00FF00</color>
I have shared this answer in the following Github chain as well- Solution.
This could be because the icon image is not transparent -- Try the notification icon generated from this tool. Also check this question Android Push Notifications: Icon not displaying in notification, white square shown instead
generate a transparent icon and then set the color in AndroidNotificationDetails parameter
You must do three things;
1.follow #user2549980's answer and do samethins step by step but in colors.xml file, you must write encoding="utf-8" with uppercase format, like;
(your notification icon must be copied mipmap folders with same sizes, and you must add that icon name to your AndroidManifest.xml, and it must be transparent icon.)
2.Step; in your local notification init function,
_notificationPlugin=FlutterLocalNotificationsPlugin();
await _notificationPlugin.initialize(
const InitializationSettings(
android: AndroidInitializationSettings('#mipmap/notification_icon'),
iOS: IOSInitializationSettings()
),
onSelectNotification: (payload) async{
},
);
you must change this line #mipmap/icon_name with your icon name.
and I am writing this comment because, this step can be missed easily so, don't forget this step.
(1) You don't have to put them in drawable, you can put them in mipmap (android/src/main/res/mip-map-**dpi folders) if you want.
(2) If you need to test the result, hotreload won't take effect, you have to rebuild to test the result.