How to deal with different icon sizes - flutter

When developing for iphone, in Xcode/Swift there is an asset file where you add all the icons your application will use with 1, 2 and 3x sizes. There is probably a similar thing with Android that I don't know yet.
When developing for Flutter:
How do you deal with the different screen resolutions to use the right icon sizes?
If similar to Xcode/Swift, where do you put those files and how do you get them? What about Android?
If you know a tutorial or web page, just let me know! The only ones that I found are only dedicated for app icon and launch screen.
Thanks

Just check the official documentation about resolution-aware-image.
This is based on the device pixel ratio.
Here you have an example about the structure of your files.
.../pubspec.yaml
.../icons/heart.png
.../icons/1.5x/heart.png
.../icons/2.0x/heart.png
And this is how you have to declare the assets files into your pubspec.file
flutter:
assets:
- icons/heart.png
This is the link: https://flutter.io/docs/development/ui/assets-and-images#declaring-resolution-aware-image-assets

To add to #diegoveloper answer.
Some plugins like google-maps do not honour this standard and require you to call BitmapDescriptor.fromAsset('icons/heart.png') which is not converted to the correct image. In this case you can get the correct image from AssetImage by first createLocalImageConfiguration using the BuildContext as defined here. Then use this configuration to resolve the correct image as follows:
ImageConfiguration config = createLocalImageConfiguration(context);
AssetImage('icons/heart.png')
.obtainKey(config)
.then((resolvedImage) {
print('Name: ' + resolvedImage.onValue.name);
});
In summary
Create an asset folder with the naming convention:
pathtoimages/image.png
pathtoimages/Mx/image.png
pathtoimages/Nx/image.png
pathtoimages/etc.
Where M and N are resolutions (2.0x) or themes (dark).
Then add the image or all the images to the pubspec.file as either
flutter:
assets:
- pathtoimages/image.png
or
flutter:
assets:
- pathtoimages/
Load the images in using either AssetImage('pathtoimages/image.png') or resolving to the actual file name as mentioned above, depending on the library being used.

Related

Display an image from the asset in the documentation

I'm writing documentation about a variable and I would like to include an image that is inside the project. For example:
assets/
|- icons/
| |- my-image.svg
lib/
|- my_file.dart
I know it is possible to display an image from an URL, but what about one from a file?
Those were my unsuccessful tries:
// lib/my_file.dart
/// The image attempt:
/// ![](assets/icons/my-image.svg)
/// ![](../assets/icons/my-image.svg)
const myVariable = 0;
But it doesn't work:
Is there a way to do it?
There is already an issue on GitHub: #2390
and also a related thread: Using local image assets in dart documentation comments
Effectively, web urls are working, but relative paths aren't, because VSCode doesn't support that. It tries to open the files relative to its application directory. But I can't confirm that for Windows either, because for me, not even absolute paths are working...
So if your project lives in a public repository anyways, you could just use a web url.
1:open pubspec.yaml and click "Pub get"
2:
Image.asset("assets/icons/my-image.svg",width: 100,height: 100,)
So i think you want to let the variable hold the asset image path so do this
Go to pubspecs.yaml file and add this
flutter:
assets:
- assets/icons/my-image.svg
Then run flutter pub get
then you can use the image this way
//let the variable hold the image path
const myVariable = "assets/icons/my-image.svg";
//to display on widget
Image.asset(myVariable);

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.

cannot display images from api response flutter

"poster_path": "/9gk7adHYeDvHkCSEqAvQNLV5Uge.jpg"
what should I use to display images like this?
I tried to use image network widget but it didn't work
if you are storing the image locally, you have to go to the pubspec.yaml file and change the dependencies for the assets. if you want to load it from a url in the internet, you can use Image.network(url) .

FlutterWeb - Display all images in a directory

I'm creating a Flutter Web app and i'm trying to figure out a way to display all images in a directory. Here's an example tree.
images
- projects
- p1
- image1.jpg
- image2.JPEG
- image3.png
- p2
I can display every image individually with Image.Asset(images/projects/p1/image1.jpg) but some image files have different extensions or are in different subfolders. Since this is flutter web I don't have access to dart:io and cant use Directory() which includes packages like 'path_provider'. Possible solution would be to create a json manifest file with all folders/filenames but some folders can have up to 20-30 files and would require me to update the manifest everytime I add/replace/remove images. Any other ideas?
you can do something like this
assets:
- images/
- fonts/
this way all of the "Direct" child's will be added to the assets but sub-child's won't so if you can make a constant structure for your assets and add only the directories then you don't have to worry about the pubspec.yaml or running flutter pub get when files are added or removed .

Icon file names iOS 7

How do I have to name the Icon files for Xcode 5?
It gives always errors that de app is not on the top level, it is really frustrating.
Can someone give me the filenames that you have to use for every resolution?
icon file name and size for ios 7 compatible app as below (iPhone)
Icon.png - 57*57
Icon#2x.png - 114*114
Icon-Small.png - 29*29
Icon-Small#2x.png - 58*58
Icon-40.png - 40*40
Icon-40#2x.png - 80*80
Icon-60#2x.png - 120*120
Icon-76.png - 76 x 76
Icon-76#2x.png 152 x 152
(EDIT: corrected names of 120 & 40 sizes, and added 76 + 152)
Asset Catalog is the best thing for setting application icons... It removes the need to follow naming conventions when you are adding or updating your app icons...
You can use this for setting splash screens & application icons..
In Xcode 5 you can find this options..
1- In the project navigator, select your target.
2- Select the General pane, and scroll to the App Icons section.
It really doesn't matter how you name them. If you're using the new catalog feature, you can just drag the icons into each slot.
I've named them in different ways and it hasn't mattered. Ex. app_icon_72.png, app_icon_144.png or app_icon72#2x.png.
Please refer this url, you will get good idea about application icons naming convention
http://developer.apple.com/library/ios/#qa/qa1686/_index.html
I have collected all required sizes for iOS 9+
Application Icon for iTunes, iPhone and iPad
for three types : App, Spotlight and Settings
including Retina and non retina screens needs Icons in following different sizes (in pixels).
29x29
58x58
40x40
50x50
58x58
76x76
80x80
87x87
120x120
152x152
167x167
180x180
512x512
1024x1024
Even Xcode guide us for this
Also you can check apple's Icon and Image Sizes guidelines
For naming convention
iOS 5 no longer requires specific file names for various icon files. HOWEVER - If you include spaces in the icon file names (or probably any other illegal non-alphanumeric character) the icon files won't work.
If you are not using Image catalog in Xcode-5 & still you are getting the error "app is not on the top level", then you are just messed with the location of your icon files. You should keep your icons files in your project folder in the same location where your PROJECT.xcodeProj file resides.
As #JackD said specific name doesn't matter's any more for ios icon. All you need is perfect size.
I have created this application which will provide you all the icons based on information provided here. Get the application from here, and follow the instructions in readme file to create all the required icons for iOS application.
This link has all the required filenames and resolutions: https://developer.apple.com/library/ios/qa/qa1686/_index.html
But noticed that under the section: "Icons for Universal Apps", the filename for both 58x58 and 87x87 are the same Icon-Small#2x.png. Anyone knows what should be the proper names for these 2 resolutions?
1) 58x58
Icon-Small#2x.png
Settings on devices with retina display
Recommended if you have a Settings bundle, optional otherwise
2) 87x87
Icon-Small#2x.png
Settings on iPhone 6 Plus
Recommended if you have a Settings bundle, optional otherwise