Image overflow in container - flutter

I am working on a Flutter app. There is a widget where I need to resize an image to fit in the container.
Here you have the code:
Expanded(
flex: 2,
child: Padding(
padding: const EdgeInsets.only(top: 0.0),
child: Column(
children: [
Container(
child: Image.asset("./assets/slide3.png",)),
],
),
),
),
And here you have the output:
How can I get the image fit the container size and avoid the bottom overflowed by 117 pixels?

this is should be a comment but ok
you need to wrap Container with Expanded
Expanded(
flex: 2,
child: Padding(
padding: const EdgeInsets.only(top: 0.0),
child: Column(
children: [
Expanded(
child: Container(child: Image.asset("./assets/slide3.png")),
),
],
),
),
),

try to use fit like this
Container(height: 200.0,child: Image.asset("./assets/slide3.png",fit: BoxFit.cover,)),

Related

Stack inside column not working. What should I use instead?

I want to create this widget. The pseudocode I tried is just like this:
Column
Container (My Widget)
Column
Image
Stack
Message Text
Positioned
Status Text
Constraints:
Status must look like it stays inside the text widget. But it shouldn't be on it.
Text and image sizes are not fixed !!!
Problem: Stack inside column without size is not working. So status text appears under the text widget as centered.
return MessageBallon(
directory: message.direction,
childElement: Column(
children: [
message.hasMedia
? Container(
padding: EdgeInsets.only(bottom: height * .05),
child: CustomMedia(
src: message.media,
),
)
: const SizedBox(),
Stack(
children: [
Container(
padding: const EdgeInsets.only(
bottom: 13,
top: 18,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
Container(
constraints: BoxConstraints(maxWidth: width * .53),
child: Text(
message.content,
style: TextStyles.normalTextBlack,
),
),
],
),
),
Positioned(
bottom: 0,
right: 0,
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Padding(
padding: const EdgeInsets.only(right: 10),
child: Text(
message.messageDate,
style: TextStyles.detailText,
),
),
message.direction == SmsDirection.incoming
? Align(
alignment: Alignment.centerRight,
child: messageStatus,
)
: const SizedBox(),
],
),
)
],
)
],
),
);
Just use Scaffold with FloatingActionButton for your status.
Rest Image and Text can be inside a column.
You can achieve something like the below only with these widgets.

Doesn't fit all content on the page Flutter

Faced a problem. My content does not fit on the page, so I added SingleChildScrollView in the TabBarLibrary. And wrapped in Expanded. As a result, I got scrolling, but also the content size greatly decreased due to Expanded, I attached a screenshot below where you can see that an empty space has appeared. How can I make the content appear on the entire page and be able to scroll?
body
Column(
children: [
const SizedBox(height: 20),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 15),
child: Column(
children: [
TabBarWidget(tabController: _tabController),
],
),
),
const SizedBox(height: 20),
_divider,
TabBarLibrary(
tabController: _tabController,
size: size,
),
],
);
TabBarLibrary
return Expanded(
child: SingleChildScrollView(
child: ConstrainedBox(
constraints: BoxConstraints(maxHeight: widget.size.height * .69),
child: TabBarView(
controller: widget._tabController,
children: [
_tab1(),
Text('Tab2'),
Text('Tab3'),
],
),
),
),
);
}
tab1
return Column(
children: [
_divider,
const Padding(
padding: EdgeInsets.only(left: 24, top: 20),
child: Align(
alignment: Alignment.centerLeft,
//TODO dropdown
child: Text(
'DrowDown',
style: TextStyle(color: Colors.white),
),
),
)
...
without Expanded
Try remove ConstrainedBox, it limit your TabBarLibrary height.
Explain: You have already Expanded to determined height and a SingleChildScrollView inside wich want to fill there height, ConstrainedBox inside that limit the height, so content will not fill full the scrollview.
try wrap Expanded with SingleChildScrollView
return SingleChildScrollView(
child: Expanded(
child: ConstrainedBox(

Is there a way to get fixed size for child inside GridView?

Is there a way to have a fixed size for the child inside GridView? I wanted to have the red color be same height. I tried using Expanded or specified the size for the Container, but it just won't work. GridView just makes the child same size.
Note: I tried specify the height for the red Container. It didn't work.
This is what I got.
This is what I did.
return GridView.count(
crossAxisCount: 2,
children: List.generate(drinksData.length, (index) {
return Container(
padding: EdgeInsets.all(20.0),
child: Column(
children: [
Expanded(
child: Container(
color: Colors.red,
),
),
Text(drinksData[index].label),
],
),
);
}),
);
GridView.count(
crossAxisCount: 2,
children: List.generate(drinksData.length, (index) {
return Container(
padding: const EdgeInsets.all(20.0),
child: Column(
children: [
Expanded(
child: Container(
// height:90,//or whatever size you want!
color: Colors.red,
),
),
SizedBox(
height: 45,
child: Text(drinksData[index])
),
],
),
);
}),
)
```

overflowing flutter columns and rows

I have this list view in flutter which I am trying to make into a chat list. Similar to what you see in WhatsApp and telegram. However I am struggling to get the idea of how rows and columns work because I keep getting overflows.
Here is the code:
ListView(
physics: BouncingScrollPhysics(),
children: [
Dismissible(
key: Key(""),
background: Container(color: Colors.grey[200]),
direction: DismissDirection.endToStart,
child: InkWell(
onTap: () {},
child: Column(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Flex(
direction: Axis.vertical,
children: [
Text("Hello"),
],
),
Flex(
direction: Axis.vertical,
children: [
Text(
"al;skdl;aksd a;skd ;aks;dk a;skd ;laks;d a;lsk d;lkas; dka;lsk d;laks; ldka;slk d;a",
overflow: TextOverflow.ellipsis,
maxLines: 2,
),
],
),
],
),
),
),
],
Now we often experience the text overflow problem so if we think it that we we have provided column a particular width and restricted it but if we wrap the things up with flexible widget it now tells column/Row that you can change your size and be flexible
order would be
flexible > Container > Column/Row
The reason we are applying this to container is Column/Row will ask immediate parent for width and height
now this problem can also be solved by text overflow property that is we can clip text but what if we dont want too
So all you have to do is Wrap the column/Row in Container and then into Flexible as now it will tell container that yes you can adjust your height
Your concept can be cleared by how actually widgets parent child relationship works i.e in brief
basically If am a child I will ask my parent okay what is my size so since my parent if it has a size it will bound me but if it doesnt has a size it will ask its parent okay tell me what space should I take and it goes on. Expanded and Flexible says that okay you can adjust yourself instead of being Fixed.
Flexible(
child: Container(
margin: EdgeInsets.only(left: 10.0,right: 10.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('${dataBookTitleSearch1[index]} ', style: kGoodSearchResultTextStyle, textAlign: TextAlign.left,),
SizedBox(
height: 10.0,
),
Text('${dataBookAuthorSearch1[index]}', style: kGoodSearchResultTextStyle,textAlign: TextAlign.left),
SizedBox(
height: 10.0,
),
Text('${dataBookExtensionSearch1[index]} ', style: kGoodSearchResultTextStyle,textAlign: TextAlign.left),
SizedBox(
height: 20.0,
),
Container(
width: 80.0,
height: 40.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(20.0)),
color: Colors.white
),
child: Padding(
padding: const EdgeInsets.only(left:20.0,top: 12.0),
child: Text('Read'),
),
),
],
),
),
)

I am getting A RenderFlex overflowed by 57 pixels on the bottom

Hi I am new to Flutter and I came across this error that is in the title I looked here as well but nothing seems to help, the layout looks just fine when I star the app however I am getting an error which drives me crazy. One of the solutions that I found was to add resizeToAvoidBottomPadding: false which I did but the error is still present.
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomPadding: false,
body: Stack(
children: <Widget>[
Container(
padding: EdgeInsets.symmetric(horizontal: 20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Expanded(
flex: 3,
child: SizedBox(),
),
_title(),
SizedBox(
height: 50,
),
_displayUserNameAndPassword(),
SizedBox(
height: 20,
),
_submitButton(),
Container(
padding: EdgeInsets.symmetric(vertical: 10),
alignment: Alignment.centerRight,
child: Text('Forgot Password ?',
style:
TextStyle(fontSize: 14, fontWeight: FontWeight.w500)),
),
_divider(),
_facebookButton(),
Expanded(
flex: 2,
child: SizedBox(),
),
],
),
),
Align(
alignment: Alignment.bottomCenter,
child: _createAccountLabel(),
),
],
),
);
}
You need to use ListView instead of Column.
In column when keyboard appears for text field it caused renderflexed overflow error.
Thanks