Related
i always build ListTile like this, the problem is the upper text 'Bluckcurrent' and the bottom text 'STOCK: 10' is not in the same line with the end of image. I want it to match the image height automatically. Sorry for my bad explanation, if you need more information please tell me i will update the question.
Container(
padding: EdgeInsets.fromLTRB(16, 8, 16, 8),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
width: 90,
height: 100,
decoration: BoxDecoration(
color: Constants.blueLightColor.withOpacity(0.2),
borderRadius: BorderRadius.circular(16),
),
child: Icon(
Icons.image_outlined,
size: 42,
color: Constants.blueLightColor,
),
),
SizedBox(width: 10),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'BLACKCURRENT MOUNT TEA',
style: TextStyle(
fontWeight: Constants.bold,
),
maxLines: 2,
),
Text(
'250ml',
style: TextStyle(
height: 1.4,
fontSize: 12,
color: Constants.greyColor,
),
),
Text(
'Rp. 8.000',
style: TextStyle(
height: 1.7,
fontWeight: Constants.bold,
),
),
Text(
'STOCK : 10',
style: TextStyle(
height: 1.7,
fontWeight: Constants.bold,
),
),
],
),
),
SizedBox(width: 16),
],
),
),
Add a sizedBox with specific height wrapping the row widget and the let the image fetch its width. And in the Column of the Text widgets add a spacer where you wish to add extra space
SizedBox(
height: 100,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.network(
"https://www.bastiaanmulder.nl/wp-content/uploads/2013/11/dummy-image-portrait.jpg",
fit: BoxFit.cover,
),
SizedBox(
width: 10,
),
SizedBox(
height: 200,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Text(
"Some title here",
style:
TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
),
SizedBox(
height: 10,
),
Text("Price: \$60"),
Spacer(),
Text(
"Stock : 10",
style:
TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
)
],
),
),
],
),
),
Just to show it will align properly, increasing the height to 200
Try: set Container height 100
child: Container(
height: 100,
padding: EdgeInsets.fromLTRB(16, 8, 16, 8),...
How about using MainAxisSize.min ?
It will fix column height to children height.
Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisSize: MainAxisSize.min,
children: [
...
],
),
try this.
since image height is dynamic, then it will align vertically with all the column children on the right side
Card(
child: Container(
padding: EdgeInsets.all(8),
width: double.infinity,
child: Stack(
children: [
Positioned(
child: SizedBox(
// no need to set height
// SizedBox will strech following widget on the right
width: 50,
child: Image.network(
'https://picsum.photos/250?image=9',
fit: BoxFit.cover, // you can modified as you need
),
),
top: 0, //
left: 0,
bottom: 0), //
Container(
margin: EdgeInsets.only(left: 60),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'WWWWWWWWWWWWWWWWW',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 18,
),
),
SizedBox(
height: 10,
),
Text("lorem ipsum"),
SizedBox(
height:5,
),
Text("lorem ipsum"),
],
),
),
],
),
),
),
You can use IntrinsicHeight widget to wrap your Row.
IntrinsicHeight(child: Row())
I have a container that is sized relative to the window size. I need my text widget, which is nested in this container to fill the size of the container, which I can do except the text all stays on one line. I want the text to wrap to that it fills the height of the container and not just its width.
This is my current code,
Container(
width: width * 2.5,
height: height,
color: Colors.white,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Padding(
padding: EdgeInsets.fromLTRB(width / 2, 0, width / 2, 0),
child: Opacity(
opacity: 0.2,
child: Image.asset(
'assets/images/${model?.imageName}',
height: centerIconHeight,
),
),
),
Flexible(
flex: 1,
child: FittedBox(
fit: BoxFit.contain,
child: Expanded(
child: Text(
model?.title ?? '',
softWrap: true,
maxLines: 10,
style: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 30,
color: Colors.cyan),
),
),
),
),
],
),
),
And this is what it looks like when I run it. Notice the text is too small because it is only on one line and matching the containers width.
FittedBox tries to fit the text in no matter of its size. Just remove it and text will be wrapped.
UPDATE:
Container(
width: width * 2.5,
height: height,
color: Colors.white,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Padding(
padding: EdgeInsets.fromLTRB(width / 2, 0, width / 2, 0),
child: Opacity(
opacity: 0.2,
child: Image.asset(
'assets/images/${model?.imageName}',
height: centerIconHeight,
),
),
),
Flexible(
flex: 1,
child: Text(
model?.title ?? '',
softWrap: true,
maxLines: 10,
style: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 30,
color: Colors.cyan),
),
),
],
),
),
I am using Gridview in my app I need to line horizontal and vertical. So I change the background color to grey but the issue it's showing some extra space how can I remove it?
Container(
color: Colors.grey,
child: GridView(
shrinkWrap: true,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisSpacing: 2,
mainAxisSpacing: 2,
crossAxisCount: 4,
),
children: <Widget>[
Container(
color: Colors.white,
child: Column(
children: [
SizedBox(height: Height * 0.01,),
Container(
height: Height * 0.04,
child: Image.asset('images/cat1.png'),
),
SizedBox(height: Height * 0.008,),
Text(
'Computer Hardware',
textAlign: TextAlign.center,
)
],
),
),
Container(
color: Colors.white,
child: Column(
children: [
SizedBox(height: Height * 0.01,),
Container(
height: Height * 0.04,
child: Image.asset('images/cat2.png'),
),
SizedBox(height: Height * 0.008,),
Text('Computer Software',
textAlign: TextAlign.center)
],
),
),
Container(
color: Colors.white,
child: Column(
children: [
SizedBox(height: Height * 0.01,),
Container(
height: Height * 0.04,
child: Image.asset('images/cat3.png'),
),
SizedBox(height: Height * 0.008,),
Text('Internet', textAlign: TextAlign.center)
],
),
),
Container(
color: Colors.white,
child: Column(
children: [
SizedBox(height: Height * 0.01,),
Container(
height: Height * 0.04,
child: Image.asset('images/cat4.png'),
),
SizedBox(height: Height * 0.008,),
Text('Mobile / Table & iPad',
textAlign: TextAlign.center)
],
),
),
Container(
color: Colors.white,
child: Column(
children: [
SizedBox(height: Height * 0.01,),
Container(
height: Height * 0.04,
child: Image.asset('images/cat5.png'),
),
SizedBox(height: Height * 0.008,),
Text(
'Printer & Scanner',
textAlign: TextAlign.center,
)
],
),
),
Container(
color: Colors.white,
child: Column(
children: [
SizedBox(height: Height * 0.01,),
Container(
height: Height * 0.04,
child: Image.asset('images/cat6.png'),
),
SizedBox(height: Height * 0.008,),
Text('CCTV Cameras', textAlign: TextAlign.center)
],
),
),
Container(
color: Colors.white,
child: Column(
children: [
SizedBox(height: Height * 0.01,),
Container(
height: Height * 0.04,
child: Image.asset('images/cat7.png'),
),
SizedBox(height: Height * 0.008,),
Text('Smart TV/Home Theater',
textAlign: TextAlign.center)
],
),
),
Container(
color: Colors.white,
child: Column(
children: [
SizedBox(height: Height * 0.01,),
Container(
height: Height * 0.04,
child: Image.asset('images/cat8.png'),
),
SizedBox(height: Height * 0.008,),
Text('E-Learning', textAlign: TextAlign.center)
],
),
),
],
),
),
You can see in the image its showing a grey color on top I need to remove this. I am not using any padding etc in container still its showing this
set gridview padding: const EdgeInsets.all(0)
I currently have a list made of Containers() (since I cannot use ListView because I need external scrolling), and it's working well except because in each of them, I have a Row(), with two Column() widgets. The first column should be limited print an image, and the second one, to show certain information in rows. It's a very typical way of doing lists, so I thought it shouldn't cause problems.
Thing is, that the second Text() widget in the second Column(), seems to always cause the upper Text() to shift to the right, causing an overflow and making the text unreadable, unreachable by the user. Look at this picture:
Yes, the titles are there (even if you can't see the second one). They are just quite shifted to the right. If I remove the description below, they show up correctly, at the left side, with just a little left padding. Thing is, these titles should be there no matter how elements are below, or at least, that's how I understand the Column() widget should work.
Take a look at the code:
getListItems(List<Artist> artistList) {
// Iterate through the whole Artists array and render a list item for each one
return artistList.map((Artist artist) {
return Container(
margin: EdgeInsets.only(top: 12),
height: 100,
color: Colors.grey[600],
child: Row(
children: <Widget>[
Padding(padding: EdgeInsets.only(left: 15)),
Column(
children: <Widget>[
Image(
width: 100,
height: 100,
fit: BoxFit.cover,
image: artist.avatar)
],
),
Padding(padding: EdgeInsets.only(top: 5)),
Column(
children: <Widget>[
Text(
artist.name,
style: TextStyle(fontSize: 18),
),
Padding(padding: EdgeInsets.only(top: 5)),
Text(artist.description, style: TextStyle(fontSize: 13))
],
)
],
));
}).toList();
What is wrong in this code? Thank you!
You can wrap the second column with Flexible to avoid overflow:
Container(
margin: EdgeInsets.only(top: 12),
height: 100,
color: Colors.grey[600],
child: Row(
children: <Widget>[
Padding(padding: EdgeInsets.only(left: 15)),
Column(
children: <Widget>[
Image(
width: 100,
height: 100,
fit: BoxFit.cover,
image: artist.avatar)
],
),
Flexible(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Text(
artist.name,
style: TextStyle(fontSize: 18),
),
Padding(padding: EdgeInsets.only(top: 5)),
Text(artist.description, style: TextStyle(fontSize: 13))
],
),
)
],
))
You need to make some modifications to the Column which contains the Text widgets
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
artist.name,
style: TextStyle(fontSize: 18),
),
Padding(padding: EdgeInsets.only(top: 5)),
Container(
width: MediaQuery.of(context).size.width * 0.5, // can change "0.5" according to your requirement
child: Text(
artist.description,
style: TextStyle(fontSize: 13),
),
),
],
)
You can use Flexible() widget Wrap your text widget in flexible widget.
return Center(
child: Padding(padding: EdgeInsets.only(left: 50, right: 50),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Flexible(
child: Text('Hii....helloo....how r u?...here you can show multiple line.', textAlign: TextAlign.center,style: TextStyle(fontSize: 20.0, color: Colors.white))),
],
),
)
);
try Expanded
getListItems(List<Artist> artistList) {
// Iterate through the whole Artists array and render a list item for each one
return artistList.map((Artist artist) {
return Container(
margin: EdgeInsets.only(top: 12),
height: 100,
color: Colors.grey[600],
child: Row(
children: <Widget>[
Padding(padding: EdgeInsets.only(left: 15)),
Column(
children: <Widget>[
Image(
width: 100,
height: 100,
fit: BoxFit.cover,
image: artist.avatar)
],
),
Padding(padding: EdgeInsets.only(top: 5)),
Expanded(
child: Column(
children: <Widget>[
Text(
artist.name,
style: TextStyle(fontSize: 18),
),
Padding(padding: EdgeInsets.only(top: 5)),
Text(artist.description, style: TextStyle(fontSize: 13))
],
),
)
],
));
}).toList();
Use Expanded
class MyWidget extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Container(
height: 100,
color: Colors.grey[600],
padding: const EdgeInsets.all(8.0),
child: Row(
children: [
Container(
width: 100,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage("https://picsum.photos/100"),
),
),
),
const SizedBox(width: 8.0),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text("Artist Name"),
const SizedBox(height: 8.0),
Text("Artist Description"),
],
),
),
],
),
);
}
}
first of all you can Define the container as a child of Expanded(the container in top of widget)
Expanded(
child:
Container(
margin: EdgeInsets.only(top: 12),
height: 100,
color: Colors.grey[600],......
or you can use
media query,media query, Defines the length or width according to the screen resolution of the phone
you gotta define media query for height or width
use the mediaqueryfor that, MediaQuery.of(context).size.height,
Container(
margin: EdgeInsets.only(top: 12),
height: `MediaQuery.of(context).size.height`,
color: Colors.grey[600],
child: Row(
children: <Widget>[
Padding(padding: EdgeInsets.only(left: 15)),
Column(
children: <Widget>[
Image(
width: 100,
height: 100,
fit: BoxFit.cover,
image: artist.avatar)
],
),
Padding(padding: EdgeInsets.only(top: 5)),
Column(
children: <Widget>[
Text(
artist.name,
style: TextStyle(fontSize: 18),
),
Padding(padding: EdgeInsets.only(top: 5)),
Text(artist.description, style: TextStyle(fontSize: 13))
],
)
],
));
}).toList();
if when you use the media query the overflowed error is showing you gotta say
MediaQuery.of(context).size.height - the pixels that error says pixels are overflowed
it means if error says overflowed by 128 pixels you gotta say
Container( height: MediaQuery.of(context).size.height -128 ,)
I am using stack to show a container but there is one issue i need to show the small date container in mid of stack.
My code
Widget _buildListItem(int index) {
double statusBarHeight = MediaQuery.of(context).padding.top;
double width = MediaQuery.of(context).size.width;
double height = MediaQuery.of(context).size.height;
return ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(20)),
child: Container(
margin: EdgeInsets.only(left: width * 0.1),
child: Stack(
children: <Widget>[
Container(
width: width * 0.6,
height: height * 0.17,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(
'assets/images/1.jpg',
),
fit: BoxFit.fill,
),
),
),
Padding(padding: EdgeInsets.only(top: height * 0.17),
child: Container(
height: height * 0.15,
color: Colors.white,
width: MediaQuery.of(context).size.width * 0.6,
child: Padding(
padding: const EdgeInsets.only(top: 7, bottom: 7, left: 7, right: 7),
child: Row(
children: <Widget>[
Column(crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
_events[index]['name'],
style: TextStyle(
color : Color(0xff000000),
fontWeight: FontWeight.bold,
fontSize: 17
),
),
Text(
_events[index]['sentence'],
style: TextStyle(
color : Color(0xff808080),
fontSize: 15
),
textAlign: TextAlign.left,
),
Text(
'${_events[index]['date']} ${_events[index]['month']} ${_events[index]['year']}',
style: TextStyle(
color : Color(0xff808080),
fontSize: 15
),
textAlign: TextAlign.left,
),
],),
Spacer(),
Icon(Icons.favorite_border, size: 20, color : Color(0xff808080),),
],
),
),
),)
],
),
),
);
}
}
Here is the output of my code
I need something this in middle of image and content
Also one thing is there is any icon in flutter or we can add borders colors in the heart as in the second image heart icon?
Positioned widget helps you position the item which is in stack.
Use the Positioned.fill with Align inside a Stack:
Stack(
children: <Widget>[
Positioned.fill(
child: Align(
alignment: Alignment.centerRight,
child: ....
),
),
],
),
Positioned(
left:10,
right:0,
top:height * 0.14,
child:Container(
height:height *0.05
padding: EdgeInsets.symmetric(horizontal: 15,vertical: 10),
decoration:BoxDecoration(
borderRadius:BorderRadius.circular(15),
color:Colors.white
),
child:Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children:<Widget>[
Text("8"),
Text("Jun")
]
)
)
)
add this to your stack as last child so its above other widgets and icon is Icons.favorite