Flutter - How should I determine the size of the image? - android

How can I determine the size of an image? For example I will use an icon for bottom navigation. Should the size of the icon be 20x20? Or is it 25x25? How can i know this?
or let's say I'm going to use a background image, what size should it be 400x800 or 600x1200. What should be the standard sizes to best optimize memory management and application size
The use of SVG is not supported by default. So I'm looking for a way to best optimize PNG or JPGs. I also separate the images as 1.5x ,2.0x, 3.0x, 4.0x and original image. But I can't decide exactly what the size of the original image will be.
For example, the debug console gives an error like this:
════════ Exception caught by painting library ══════════════════════════════════
Image assets/images/2.0x/login_picture.png has a display size of 414×516 but a decode size of 828×707, which uses an additional 1936KB.
Consider resizing the asset ahead of time, supplying a cacheWidth parameter of 414, a cacheHeight parameter of 516, or using a ResizeImage.
════════════════════════════════════════════════════════════════════════════════

Well, it is a good practice to use 1.0x, 2.0x and 3.0x images, you should either ask your designer to give you images with those sizes in .png or go to figma or photoshop and export 2.0x and 3.0x assets
For the debug error you should use fit: BoxFit.fill like here
Scaffold(
backgroundColor: AppColor.backgroundPrimaryColor,
body: Container(
margin: const EdgeInsets.only(top: 100),
decoration: BoxDecoration(
image: DecorationImage(
fit: BoxFit.fill, //Important
image: AssetImage(BackgroundImages.backgroundShapes)
),
),
)
);

Related

blendMode.dstATop makes screen black on my Android Phone

I have an app where I put the Scaffold of the screen inside a container, the container has a BoxDecoration with a DecorationImage, I want to reduce the opacity of the image, so here is the code:
decoration: BoxDecoration(
image: DecorationImage(
image: const AssetImage('assets/images/building.jpg'),
colorFilter: ColorFilter.mode(
Colors.black.withOpacity(0.2), BlendMode.dstATop),
fit: BoxFit.cover)),
This works well on the web browser, but if I try it on my android phone the screen has a black tone like it is dimmed.
I tried replacing the color with white which didn't seem to make a difference, I also tried to higher the opacity and it made the background image not transparent, which makes it hard to see text.

Flutter, Android and IOS bottom navigation bar size is different

An overflow error occurred due to the bottom navigation bar height in ios, the layout that worked well on all Android devices.
It seemed to be because of the extra space because of the format of turning off the app by pulling it up from the bottom, which is governed by the IOS operating system.
it is super annoying I forcibly increased the bottom navigation bar height because of IOS, but the design is now bad in Android. Anyone know how to solve it?
--UPDATE
Scaffold(
bottomNavigationBar: Container(
height: 50,
child: BottomNavigationBar(
...
),
),
)
Try add SafeArea on top of Container :
Scaffold(
bottomNavigationBar: SafeArea(
child: Container(
height: 50,
child: BottomNavigationBar(
...
),
),
),
)
You can easily make height different for both platforms:
height: Platform.isIOS ? 50:40
So here if the Platform is IOS the height will be 50 or it will be 40.
Hey i tried custom painter and i realized that for iphone 13 the height is 90 pixel for bottom navigation bar and for android the height is different which is the value of kBottomNavigationBarHeight. So i declared this value in my constant file such as double btmNavigationBarHeight = Platform.isAndroid ? kBottomNavigationBarHeight : 90;. Hope it helps anyone with the same problem

How to set size for launch screen icon?

I am trying to setup a launch screen that will flow seamlessly into a personal splash screen in flutter.
The goal is that I have the logo, centered on both Launch and Splash, that is lets say 10px from both left and right of a portrait only app.
I don't understand what image size I would need to be able to set this up properly on Android. I have drawable-**** folders with varied sizes but they don't fit correctly. Other than 'centering' the image in the Android xml I don't know how I would make it 'fit width' basically.
On iOS my icons show up as centered in the LaunchScreen.storyboard but are super tiny (96x96). If I manually resize the image to fit the way I want(in Xcode view scene), when I run the app I get a warning saying that the view does not have unlatching constraints and it will be shown as the original small size.
launch screen icon use fit function
for example
return Scaffold(
appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
),
body: Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: Image.asset('repo/intro.jpg' width: 100 , height: 100, fit: BoxFit.fill,),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
https://api.flutter.dev/flutter/painting/BoxFit-class.html
apple launch Storyboard use fit too

Flutter, Best way to optimise material sizes based on screen resolution/dpi?

I am currently coding a android application using flutter, dart. I have a settings page that gives the user the ability to change theme. I have created 7 identical Raw Material Button in the shape of a circle. I have been reading around the best way to size the circle base on the users resolution/dpi.
themeButton.dart:
final _themeColour;
final VoidCallback _onPressed;
ThemeButton(this._themeColour, this._onPressed);
#override
Widget build(BuildContext context) {
double width = MediaQuery.of(context).size.width;
double height = MediaQuery.of(context).size.height;
double ratio = width/height;
return RawMaterialButton (
shape: CircleBorder(),
fillColor: _themeColour,
elevation: 0.0,
highlightElevation: 0.0,
onPressed: () => _onPressed(),
splashColor: Colors.transparent,
highlightColor: Colors.transparent,
constraints: BoxConstraints(minHeight: width * ratio * 0.2),
);
}
At the moment I currently take the users device width and then size the button from that. When I try to look this up, everywhere talks about Pixel Density, however we I tried to use the dpi value as a multiplier the circles were extremely large on high dpi devices.
Using the device width works to a certain extent, however I would like to know if there is a preferred standard to completing this task.
Flutter handles high dpi automatically for you; see the devicePixelRatio documentation.
Multiplying by DPI will do it twice (which is why you're seeing them be larger on high dpi devices), whereas if you just set a width that happens automatically. What doesn't happen automatically is resizing to different aspect ratios, but it seems as though you've already come up with a solution to that. I'm not sure if there's anything else you're trying to do that doesn't accomplish - let me know and maybe I can help.
For anyone else dealing with a problem like this, the flutter wiki has an entry that might be helpful.

What is the default unit of style in React Native?

I am contributing to an Open Source Project where I am developing Material design for React Native. I am blocked at work,I am unable to make some UI level enhancements w.r.t. padding, alignment etc.,
This is the Official Spec of Material Design for Drawer-
In the above image, the UNIT of measurement is dp.
But, in my React Native code, I see there is no such units mentioned. Considering it is "react native" I am confused whether it is px or dp.
I even went over the Official Docs of React Native for Style component. I don't see a mention anywhere.
My Code looks like-
const styles = {
touchable: {
paddingHorizontal: 16,
marginVertical: 8,
height: 48
},
item: {
flex: 1,
flexDirection: 'row',
alignItems: 'center',
},
icon: {
position: 'relative',
},
value: {
flex: 1,
paddingLeft: 34,
top: 2
},
label: {
top: 2
}
},
Please can you tell me, if this is pixels or dp? And also, is 1px = 1dp?
From the docs:
All dimensions in React Native are unitless, and represent
density-independent pixels. Setting dimensions this way is common for components that should always render at exactly the same size, regardless of screen dimensions.
So yes, units in React Native are in dp. If you want to convert them to pixels, use PixelRatio.getPixelSizeForLayoutSize()
I share your confusion somewhat, not being able to actively inspect with a developer console as we are used to in the browser.
I am not familiar with the 'dp' unit, but from what I gather width: 1 renders differently on each device depending on the pixel density of the screen (see link). The information in the react-native docs say that 1 would render thicker on screens with high pixel density. Which then sounds logical as you have more precision on high density screens than you would have on low density screens and react-native aims at being universal so it would not assume high dpi.
It is my understanding that you can use the below linked PixelRatio API to calculate sizes for detail elements (think borders, icons, etc), that way you can dynamically adjust the rendered size according to the device's screen density.
https://facebook.github.io/react-native/docs/pixelratio.html#content
It is the pixel ratio that you have to consider. pixel represents an absolute value. pixel ratio is a relative value. to make app screen and components responsive you have to use pixel ratio.
i have been using in multiple apps already. and i think that is how you have to do it. hope this answers your question.
From what I know, the javascript styling that we use in react js or react native uses pixels. Pixel ratio is only needed to support different size of mobile device screens.

Categories

Resources