How to resize an image that is possitioned in a BoxDecoration flutter? - flutter

I am wondering if it is possible to resize an image that is inside of a BoxDecoration container and called by the AssetImage().
My code is:
Flexible(
child: Container(
height: size.height * .75,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(25.0),
image: DecorationImage(
image: AssetImage('assets/img/washing.png'),
fit: BoxFit.scaleDown,
)),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Container(
and follows...
The image is too big. I would like it small and in the top right corner.
Thank you.

Its size depends on your container Size. If you reduce of your container size then The image size automatically reduced. But you must use BoxFit.cover as fit
Here is the code sample -
return Scaffold(
appBar: AppBar(
title: Text('Help'),
),
body: Center(
child: Container(
height: MediaQuery.of(context).size.height * .5,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(25.0),
image: DecorationImage(
image: AssetImage(
'asset/images/download.jpg',
),
fit: BoxFit.cover,
),
),
),
),
);
If you want to developed it without Decorated image I can help you. Please share your sample UI, I will created for you

Related

Flutter - Image have overflow despite the defined width?

Is my network image still overflowing, despite the defined width, and why?
Here is a problematic part of the code:
Container(
height: 200,
width: MediaQuery.of(context).size.width, // This may be helpful, but not in my case...
decoration: BoxDecoration(
image: DecorationImage(
fit: BoxFit.fitWidth,
image: NetworkImage("${module['thumbnail']}"),
),
),
),
How to fix overflow?
A RenderFlex overflowed by 28 pixels on the right.
Help, I am a newbie in Flutter. Thanks!
Ps. Updated code from top to problematic :
Widget build(BuildContext context) {
return InkWell(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SingleModule()),
);
},
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5.0),
),
clipBehavior: Clip.antiAlias,
child: Row(
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
height: 200,
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
image: DecorationImage(
fit: BoxFit.cover,
image: NetworkImage("${module['thumbnail']}"),
),
),
),
Try putting padding: EdgeInsets.only(right: 28), to your Container that wrap around your Image Widget.

How to make Transparent Circle inside colored rectangle

I am new in flutter. I want to make the transparent Circle in side the semi transparent rectangle. Look like below,
I have not idea about that. So please help me to make this type of widget in flutter.
Using ColorFiltered and Stack you can achieve this.
(I took the answer mentioned in the comment and edited to your needs)
#override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
fit: StackFit.expand,
children: [
Image.network(
'https://lh3.googleusercontent.com/proxy/_wrP_GRGOkGw0FLMiR3qeMzlyC-qN8Dd4sND89_xxLZMDIZh204g8PCccS-o9WaL1RKyiVOLGVS9QpodSkMMhOh8kbNh1CY492197-im-4vlFRRdsVqT2g4QbRlNgljDIg',
fit: BoxFit.cover,
), //Give your Image here
ColorFiltered(
colorFilter: ColorFilter.mode(
Colors.black.withOpacity(0.5),
BlendMode.srcOut,
), // This one will create the magic
child: Stack(
fit: StackFit.expand,
children: [
Container(
decoration: BoxDecoration(
color: Colors.black,
backgroundBlendMode: BlendMode.dstOut,
), // This one will handle background + difference out
),
Align(
alignment: Alignment.center,
child: Container(
height: MediaQuery.of(context).size.width,
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(
MediaQuery.of(context).size.width / 2,
),
),
),
),
],
),
),
],
),
);
}

My container's color property doesnt work and it doesnt give any error Flutter

I have a profile page layout as its seperated by 2 and 1 positioned for avatar picture. my down container color, ı cant set it seems not working ıdk why. here is my code below:
body: new Stack(
children: <Widget>[
new Column(
children: <Widget>[
new Container(
height: topWidgetHeight,
decoration: BoxDecoration(
image: new DecorationImage(image: new AssetImage("assets/9.jpg"),
fit: BoxFit.cover)
),
),
new Container(
color: Colors.red,
)
],
),
new Positioned(
child: new Container(
height: 150,
width: 150,
decoration: BoxDecoration(
image: new DecorationImage(image: new AssetImage("assets/0.jpg"),
fit: BoxFit.cover),
borderRadius: BorderRadius.all(Radius.circular(75.0)),
boxShadow: [
BoxShadow(blurRadius: 7.0, color: Colors.black)
],
),
),
left: (MediaQuery.of(context).size.width/2) - avatarRadius,
top: topWidgetHeight - avatarRadius,
)
],
)
the container is not appearing because you have not given any height and to container
please give it height and width and then try

How to remove space between image and text in Flutter

I want to display the text (Facebook) exactly below the image (fb icon) without any spacing. Below is the code as of now :
#override Widget build(BuildContext context) {
return Scaffold(
// prevent pixel overflow when typing
resizeToAvoidBottomPadding: false,
body: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(
"assets/login_background.png",
),
fit: BoxFit.cover)),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
// mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Image(
image: AssetImage("assets/fb_icon.png"),
width: 180.0,
height: 250.0,
),
new Text('Facebook.',
style: TextStyle(
fontStyle: FontStyle.italic,
color: Colors.white,)),
_textFields(),
_signInButton(),
_socialMediaSignIns(),
_accountButtons()
],
),
),
);
}
}
Currently, I see like this and would like to remove the space between image and text.
Actually you should use BoxFit.cover to see that in effect because image has got less physical height than what is being allocated to it.
Here is the solution
Image(
image: AssetImage("assets/fb_icon.png"),
width: 180.0,
height: 250.0,
fit: BoxFit.cover,
),
You could try other BoxFit to see which one suits you better.
Image(
image: AssetImage("assets/fb_icon.png"),
),
Text('Facebook.',
style: TextStyle(
fontStyle: FontStyle.italic,
color: Colors.white,))
It has to be no padding in this case. You can check padding exactly in png file such way:
Image(
image: AssetImage("assets/fb_icon.png"),
color: Colors.red,
colorBlendMode: BlendMode.multiply,
),
This will show real borders of your image

How do I make a full screen background image that can be translated without gaps

This creates a full screen background image that can be moved with margin, but it creates a blank sliver on the bottom.
Container(
margin: EdgeInsets.only(bottom: 50),
child: Container(
decoration: BoxDecoration(
color: snapshot.data.color,
image: DecorationImage(
image: AssetImage("assets/overlay.png"),
fit: BoxFit.cover,
),
),
),
),
How can I create a full screen background image that is slightly larger than the viewport and be able to move it around without any clipping or gaps?
This is an example code of how to set full background image try this
return new Container(
child: new Stack(
children: <Widget>[
new Container(
decoration: BoxDecoration(
// color: snapshot.data.color,
image: DecorationImage(
// image: AssetImage("assets/overlay.png"),
image: NetworkImage('http://www.vactualpapers.com/web/images/April-28-2016/Glitters%20in%20the%20Air%20HD%20Mobile%20Wallpaper.jpg'),
fit: BoxFit.cover,
),
),
),
new Scaffold(
appBar: new AppBar(
title: new Text('Full Background img'),
backgroundColor: const Color(0xFF121F2B),
),
backgroundColor: Colors.transparent,
body: new Center(
child: new Text('Hello How are you?',
style: new TextStyle(fontSize: 20.0, color: Colors.white),),
),
)
],
),
);