Flutter image container, images next to each other - flutter

I'm trying to make a home page and create this image container, of three images next to each other.
I tried doing it like this:
Container(
height: 100.0,
width: 150.0,
child: Row(
children:[
Image(image: AssetImage('')),
Column(
children:[
Image(image: AssetImage('')),
Image(image: AssetImage('')),
],
),
],
),
),
what I get looks like this
while what I want is this
Although the results are nothing like this. Any ideas on how to recreate my figma image?

On your Image widget, provide height and weight and also use fit: BoxFit.cover, for better view, then it will be good to go.
Your fine Container will be
Container(
height: 100.0,
width: 150.0 + 4, //for padding
color: Colors.green,
child: Row(
children: [
Padding(
// for rounded border
padding: const EdgeInsets.only(right: 2.0),
child: ClipRRect(
borderRadius: BorderRadius.circular(12),
child: const Image(
image: AssetImage('assets/images/p7_image_asset.jpeg'),
width: 150 / 2,
height: 100.0,
fit: BoxFit.cover,
),
),
),
Column(
children: [
Padding(
// space between items
padding: const EdgeInsets.only(left: 2.0, bottom: 2),
child: ClipRRect(
borderRadius: BorderRadius.circular(12),
child: Image(
image:
AssetImage('assets/images/p8_image_asset.jpeg'),
fit: BoxFit.cover,
height: 100 / 2 - 2, //-2 for padding
width: 150 / 2,
),
),
),
Padding(
padding: const EdgeInsets.only(left: 2.0, top: 2),
child: ClipRRect(
borderRadius: BorderRadius.circular(12),
child: Image(
image:
AssetImage('assets/images/p9_image_asset.jpeg'),
fit: BoxFit.cover,
height: 100 / 2 - 2, //-2 for padding
width: 150 / 2,
),
),
),
],
),
],
),
),
I will encourage to go flutter.dev and learn about these widgets. If you are wanting GridView checkflutter_staggered_grid_view

Related

Flutter Image in Card Widget does not fill the whole card

I want to have a glass look background for my cards. When I pass the container in the card widget, the image is in the middle and too small.
Example:
Example of how it looks
My build method:
final width = MediaQuery.of(context).size.width;
final height = MediaQuery.of(context).size.height;
return Card(
elevation: 6,
color: backgroundColor,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(14),
),
child: InkWell(
onTap: () {},
child: Container(
width: width / 1.6,
height: height / 4,
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/card/test.png'),
fit: BoxFit.fitWidth,
alignment: Alignment.topCenter,
),
),
child: Padding(
padding: const EdgeInsets.only(left: 16.0, right: 16.0, top: 15, bottom: 0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(groupData.name, overflow: TextOverflow.ellipsis,),
Text(groupData.moduleId, overflow: TextOverflow.ellipsis,),
Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(child: Text(moduleData.name, overflow: TextOverflow.ellipsis,)),
Image.asset('assets/images/card/group_card_icon.png', height: 60, width: 60, fit: BoxFit.cover,)
],
)
],
),
),
),
),
);
Maybe it's not a code problem and your test.png image has empty transparent space surrounding the actual glass-like background, i just copy pasted your code but changed the fit to BoxFit.fill in your DecorationImage and it works well:
When you want to fill the image in a complete area you need to use fill, replace this with your decoration part of the decoration.
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/card/test.png'),
fit: BoxFit.fill,
alignment: Alignment.topCenter,
),
),

how to resolve flutter stack widget problems

SizedBox(
width: ScreenUtil().setWidth(197),
height: ScreenUtil().setHeight(117),
child: ClipRRect(
borderRadius: BorderRadius.circular(ScreenUtil().radius(30)),
child: Stack(
clipBehavior: Clip.none,
fit: StackFit.expand,
children: [
Image.asset(
"assets/images/image2.png",
fit: BoxFit.cover,
),
Positioned(
right: -15,
top: -15,
child: Container(
height: 50,
width: 50,
decoration: BoxDecoration(
color: Colors.orange,
borderRadius: BorderRadius.circular(15),
),
),
),
Positioned(
bottom: 10,
left: 12,
child: Text("naber lan"),
)
],
),
),
)
Why doesn't it go over the edges?Flutter inspector see outside but emulator same problem what can I do pls help what should i do.I tried everything
you are almost there but I think you miss the cliprect concept, when you used outside of stack it's clipping widget, you just put it inside stack.
Center(
child: SizedBox(
width: 197,
height: 117,
child: Stack(
clipBehavior: Clip.none,
fit: StackFit.expand,
children: [
ClipRRect(
borderRadius: BorderRadius.circular(30),
child: Image.asset(
"assets/images/test.jpg",
fit: BoxFit.cover,
),
),
Positioned(
right: -15,
top: -15,
child: Container(
height: 50,
width: 50,
decoration: BoxDecoration(
color: Colors.orange,
borderRadius: BorderRadius.circular(15),
),
),
),
Positioned(
bottom: 10,
left: 12,
child: Text("naber lan"),
)
],
),
),
)
output:

how to position an image on top of another "card"?

This is my first time here
I face a little problem which is the image that I wanted to put on top of the card do not work properly, the rest of it didn't display
I used (stack & positioned)
What should I do ??
Note : I'm beginner 👀
this is the code :
SizedBox(
width: 500,
height: 100,
child: Container(
child: Padding(
padding:
EdgeInsets.symmetric(horizontal: 10, vertical: 10),
child: Card(
color: Colors.grey.shade400,
child: Stack(children: [
Positioned(
bottom: 40,
left: 150,
child: CircleAvatar(
child: ClipOval(
child: Image.asset(
"assets/images/guy.jpg",
width: 100,
height: 100,
fit: BoxFit.cover,
),
),
backgroundColor: Colors.transparent,
radius: 50,
),
),
]),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15),
),
elevation: 10),
),
)),
and this is the the output :
enter image description here
and i wanted to be like this : enter image description here
if you want like that, then you need to put SizedBox and add size (height and or width) on it it acts as invicible widget to put space on it.
Stack
--Positioned (top 0)
----Column
------SizedBox (add height here around 50x50 px)
------Image (100x100 px)
--Card
Try below code hope its helpful to you. refer for thar Stack class here
Stack(
alignment: Alignment.topCenter,
children: <Widget>[
Padding(
padding: EdgeInsets.only(top: 10),
child: Container(
height: 320,
width: 420,
margin: EdgeInsets.all(16.0),
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
color: Colors.white,
child: Padding(
padding: const EdgeInsets.all(18.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisSize: MainAxisSize.min,
children: [
Text(
'Your Other Widgets',
),
],
),
),
),
),
),
Container(
width: 50,
height: 50,
decoration: ShapeDecoration(
shape: CircleBorder(),
color: Colors.transparent,
),
child: Padding(
padding: EdgeInsets.all(1),
child: DecoratedBox(
decoration: ShapeDecoration(
shape: CircleBorder(),
image: DecorationImage(
fit: BoxFit.cover,
image: AssetImage(
'assets/images/1.png',
),
),
),
),
),
)
],
),
Your Result screen->

Flutter how to set container on other container with stack

I have simple 2 widget is Stack i need to show the second widget on the end of first widget
Some thing like this
Here is my code
Stack(
children: <Widget>[
Container(
padding: EdgeInsets.only(top: statusBarHeight * 0.8),
height: height * 0.4,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(
'assets/images/place2.jpg',
),
fit: BoxFit.fill,
),
),
),
Align(
alignment: Alignment.bottomCenter,
child: ClipRRect(
borderRadius: BorderRadius.only(
topRight: Radius.circular(30), topLeft: Radius.circular(30)),
child: Container(
decoration: BoxDecoration(
color: Colors.white,
),
child: Column(
children: <Widget>[
SizedBox(
height: height * 0.03,
),
Container(
height: height * 0.01,
width: width * 0.1,
color: Colors.pink,
),
SizedBox(
height: height * 0.031,
),
Container(
width: width,
margin: EdgeInsets.only(left: 10),
child: Text(
'PLACES',
textAlign: TextAlign.left,
style: TextStyle(fontSize: 30),
),
),
SizedBox(
height: height * 0.02,
),
Places(),
Places(),
Places(),
Places(),
Places(),
],
),
),
),
)
],
),
In this code the second widget overlaps with first widget and cover the whole screen. I just need to show it and the end of first widget
The widget you are looking for is Positioned.
You use it like
Stack(
children: [
//Behind container, fill screen (can also use Positioned.fill)
Positioned(top:0, left: 0, right: 0, bottom: 0, child: Container()),
//Front most container, aligned bottom, full width
Positioned(left: 0, right: 0, bottom: 0, child: Container()),
]
)
you are doing correctly but because of Column widget size you are got getting your desire output.
You can give mainAxisSize to MainAxisSize.min, so it will only take space which that widget require.
child: Column(
mainAxisSize: MainAxisSize.min, // added line
children: <Widget>[
if Your widget size if big and then also you want same behaviour then you can give height to container and wrap column with SingleChildScrollView.
Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Container(
height: 200,
width: double.infinity,
child: Text("Text"),
),
Container(
height: MediaQuery.of(context).size.height * 0.7,
decoration: BoxDecoration(
color: primaryColor,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(35),
topRight: Radius.circular(35))),
),
],
),
setting the MainAxisAlignment of Column to MainAxisAlignment.end pushed the container at bottom and gave me the results i wanted.

Why is there a white line between 2 containers flutter

I am making a drawer for my app and it has 2 containers in the column widget, there seems to be a line in between these containers that ruins the appearance, i have tried this for the upper container
margin: EdgeInsets.only(bottom: 0),
padding: EdgeInsets.only(bottom: 0),
and this for the lower container
margin: EdgeInsets.only(top: 0),
padding: EdgeInsets.only(top: 0),
still the line remains. How to remove that line, any help would be appreciated. Here is the code for the drawer:
Drawer(
child: Column(
children: <Widget>[
Container(
height: globals.heightofdevice * 0.30,
width: double.infinity,
margin: EdgeInsets.only(bottom: 0),
padding: EdgeInsets.only(bottom: 0),
child: Stack(
children: <Widget>[
Image.asset(
'./images/drawerbackground.jpg',
fit: BoxFit.fitWidth,
),
Positioned(
left: globals.widthofdevice * 0.07,
bottom: 20,
child: Text(
globals.username,
style: GoogleFonts.quicksand(
textStyle: TextStyle(
// fontWeight: FontWeight.w700,
fontSize: 32,
color: Colors.white,
),
),
),
)
],
),
),
Container(
height: globals.heightofdevice * 0.70,
margin: EdgeInsets.only(top: 0),
padding: EdgeInsets.only(top: 0),
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [Colors.redAccent, Colors.white],
begin: Alignment.bottomCenter,
end: Alignment.topCenter,
),
),
child: Stack(children: <Widget>[
Image.asset(
'./images/uni.jpg',
fit: BoxFit.cover,
width: double.infinity,
),
Column(
children: <Widget>[
listTileBuilder(Icons.history, 'History'),
listTileBuilder(Icons.info_outline, 'About the app'),
listTileBuilder(Icons.account_circle, 'Logout'),
listTileBuilder(Icons.exit_to_app, 'Exit'),
],
),
]),
)
],
),
)
You can clearly see the problem in this picture
it must be something with the image or the stack
another example lets try
return Scaffold(
appBar: new AppBar(
title: new Text("Drawer"),
),
drawer: Drawer(
child: Column(
children: <Widget>[
Container(
color: Colors.yellow,
height: MediaQuery.of(context).size.height * 0.30,
width: double.infinity,
child: new Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("./images/drawerbackground.jpg"), fit: BoxFit.fill)),
child: new Align(
alignment: Alignment.bottomLeft,
child: new Padding (
padding: EdgeInsets.only(left: 20.0, bottom: 10.0),
child: Text(
"globals.username",
style: TextStyle(color: Colors.white),
),
),
),
),
),
Container(
height: MediaQuery.of(context).size.height * 0.70,
width: double.infinity,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("./images/uni.jpg"), fit: BoxFit.fill),
gradient: LinearGradient(
colors: [Colors.redAccent, Colors.white],
begin: Alignment.bottomCenter,
end: Alignment.topCenter,
),
),
child: Column(
children: <Widget>[
listTileBuilder(Icons.history, 'History'),
listTileBuilder(Icons.info_outline, 'About the app'),
listTileBuilder(Icons.account_circle, 'Logout'),
listTileBuilder(Icons.exit_to_app, 'Exit'),
],
),
)
],
),
),
body: Container(
child: Text('Add Moka'),
),
);
The problem is most likely the fact that your top widget's image is set to fit: BoxFit.fitWidth,. Since it is trying to fill the horizontal plain fully it will stop once it has done so and not scale vertically to cover the remaining white space.
To fill the space of the container not taken by your image with a color so it isn't a white line you can try this (changes background to black):
Container(
height: globals.heightofdevice * 0.30,
width: double.infinity,
margin: EdgeInsets.only(bottom: 0),
padding: EdgeInsets.only(bottom: 0),
colors: Colors.black, // Added color
child: Stack(
...
),
),
Or to try and make the image take up all the available space of the container, regardless of the image's size and aspect ratio you can change the BoxFit to fill:
Image.asset(
'./images/drawerbackground.jpg',
fit: BoxFit.fill, // BoxFit fill
),