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.
Related
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)
),
),
)
);
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
I am using flutter 2.0.4 and dart 2.12.2
I use following code to add blur effect.
It is working fine on Android but does not provide blur effect on iOS devices.
Is there any work around for this ?
Or is there some minimum version of iOS this is working?
Container(
width: SizeConfig.screenWidth,
height: SizeConfig.screenHeight,
child: ClipRect(
child: BackdropFilter(
filter: ImageFilter.blur(
sigmaX: 5.0,
sigmaY: 5.0,
),
child: Container(
width: SizeConfig.screenWidth,
height: SizeConfig.screenHeight,
decoration: BoxDecoration(
color: Colors.grey.shade200.withOpacity(0.5)),
),
),
),
)
on Android blur effect is active
on iOS grey shading is active but blur effect is not active
Can anyone provide some solution for this?
This has been a long running issue with seemingly no fix yet and seems specific to certain use cases.
More on it here
If you haven't already tried this, what I would rather suggest is to try creating a Stack and have your your Container on top of whatever view your are trying to blur.
I am trying to get a frosted glass effect on top of a widget and i used a BackdropFilter and the desired effect was met. but then i figured out that made my app so laggy especially when scrolling the widget that had the filter effect on top.
here is my BackdropFilter sample :
ClipRect(
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: blurPower!=null?blurPower.key:2, sigmaY: blurPower!=null?blurPower.value:3),
child: Container(
decoration: BoxDecoration(
color: blurColor??Colors.grey.shade100.withOpacity(0.2),
borderRadius: BorderRadius.all(borderRadius??Radius.circular(10)),
border: Border.all(width: .3, color: MyTheme.bgBottomBar),
)
),
),
)
without the BackdropFilter my FPS is around 32fps but with it on it gets to 7fps on average and that is unacceptable.
my question is a way to mitigate the fps drop or a way to get the same effect in an other way.
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