Flutter Image not shrinking when window gets smaller - flutter

I have a flutter image that is not shrinking as the window shrinks:
Widget build(BuildContext context) {
return Expanded(
flex: 1,
child: Column(
//mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
ConstrainedBox(
constraints: const BoxConstraints(maxHeight: 500, maxWidth: 600),
child: ClipRRect(
borderRadius: BorderRadius.circular(15.0),
child: Image.asset(
'images/DontForgetTheSpoon-largeLogo.jpg',
),
),
),
I tried to use boxFit.contain in the Image.Asset but that didn't seem to work out for me. Anything else I should be looking into?
This widget is inside other widgets just for SA.

Try to use fit property of image Widget, inorder to have image shrink try use value BoxFit.contain:
ClipRRect(
borderRadius: BorderRadius.circular(15.0),
child: Image.asset(
'images/DontForgetTheSpoon-largeLogo.jpg',
fit: BoxFit.contain,
),
),

Related

SingleChildScroll adding a large inset on-top of the Keyboard

I'm trying to create a scrollable register form for a Flutter app. I got SingleChildScroll to work, but theres a large padding or inset or something on top of the keyboard that can block content. You can see if pretty well If I scroll all they way to the bottom.
Here's my code.
Widget _buildContainer() {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ClipRRect(
// This Clips the border Radius of the Container
borderRadius: const BorderRadius.all(
Radius.circular(20),
),
child: Container(
// This sets the attributes of the Container
height: MediaQuery.of(context).size.height * 0.69,
width: MediaQuery.of(context).size.width * 0.9,
decoration: const BoxDecoration(
color: Colors.white,
),
child: Scaffold(
body: SingleChildScrollView(
child: Form(
key: _formKey,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
_buildFirstNameRow(),
_buildLastNameRow(),
_buildEmailRow(),
_buildPasswordRow(),
_buildConfirmPasswordRow(),
_buildRegisterButton(),
],
),
),
),
),
),
),
],
);
}
I've tried setting resizeToAvoidBottomInset: false, in the Scaffold, but that prevents any scrolling from happening.
I've also tried adding to Scaffold as well, but that only changes the padding around that mystery inset.
body: Padding(
padding: EdgeInsets.only(
bottom: 8.0),
Thanks for your Help!

Remove (what seems like) margin around widget in Container

I'm having trouble removing the vertical space around the 'ClipOval' widgets within this Column. My goal (at this moment) is to have no space between them but I can't seem to figure out how to accomplish that.
Column(
mainAxisSize: MainAxisSize.max,
children: [
ClipOval(
child: SizedBox.fromSize(
size: const Size.fromRadius(100), // Image radius
child: Image.asset('assets/images/home_logo.png', fit: BoxFit.cover),
),
),
ClipOval(
child: SizedBox.fromSize(
size: const Size.fromRadius(100), // Image radius
child: Image.asset('assets/images/home_logo.png', fit: BoxFit.cover),
),
)
],
)
I tried creating a custom clipper but it would have the image removed entirely. Here's the code I tried for the clipper. My approach here was having the top margin set to 0 in hopes of having the top margin removed.
class MyClip extends CustomClipper<Rect> {
Rect getClip(Size size) {
return Rect.fromLTWH(100, 0, 100, 100);
}
bool shouldReclip(oldClipper) {
return false;
}
}
Try using CircleAvatar with ClipRRect instead.
Sample Code
Column(
mainAxisSize: MainAxisSize.max,
children: [
CircleAvatar(
radius: 100,
child: ClipRRect(
child: Image.asset('assets/images/home_logo.png'),
),
),
CircleAvatar(
radius: 100,
child: ClipRRect(
child: Image.asset('assets/images/home_logo.png'),
),
),
],
),
Hope this help.
Explanation
On your current approach you have a Sizebox with
size: const Size.fromRadius(100) while you have a small image less than the Sizebox size
You could also try to replace BoxFit.contain to BoxFit.fill but this will stretch your image
Column(
mainAxisSize: MainAxisSize.max,
children: [
ClipOval(
child: SizedBox.fromSize(
size: const Size.fromRadius(100), // Image radius
child: Image.asset('assets/images/home_logo.png',
fit: BoxFit.fill),
),
),
ClipOval(
child: SizedBox.fromSize(
size: const Size.fromRadius(100), // Image radius
child: Image.asset('assets/images/home_logo.png',
fit: BoxFit.fill),
),
),
],
),
Have you tried changing the value of mainAxisAlignment: to mainAxisAlignment: MainAxisAlignment.start and crossAxisAlignment: CrossAxisAlignment.start

Move container to the left

I want the container to be in the left side but i am always getting in the center of the screen. I tried using alignment and also used row,column but nothing worked.
Widget _guitarChord(BuildContext context) {
return GestureDetector(
child: Container(
height: 200,
width: 250,
decoration: const BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(12)),
image: DecorationImage(
image: AssetImage('images/worship.jpg'), fit: BoxFit.cover)),
),
onTap: () {},
);
}
I use your method as a child in a column in my body. Pay attention you should add these codes in your column before your children. avoid using of Center widget
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_guitarChord(context),
const Text('KM flutter',style: TextStyle(fontSize: 25),),
],
),

Widget which adjusts to the children size?

Is there a widget in Flutter which adjusts itself on the content of it's children which are in Rows and Columns?
I can't seem to find anything related, and I am constantly hit with infinite overflows errors.....
As an example, lets say I would have 3 Widgets in a Row, 1 of which is a text, which I cannot guess how long it will be, but I need to expand the parent as much as the widget needs and at the sametime wrap the text
I would have something like:
Row(
children: [
Expanded(child: Widget1(....)),
Expended(child: Text(.....)),
Expanded(child: Widget2(....))
]
)
Right?
I would want the parent of the row to expand as much as it needs for the children to be shown, I want to align Widget1 and Widget2 in different ways (1-center, 2-bottom).
If I put them in Column I can center Widget1, but I cannot put Widget2 at the bottom because if I put Column to max size it overflows, if I don't it doesn't align...
How would you do it?
I really don't understand the logic behind the inifnite layout thing....
For example, here is where I am stuck at the moment.
return Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Container(
padding: EdgeInsets.all(10),
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Global.findCategory(event.categId).color.withAlpha(150),
blurRadius: 20,
spreadRadius: -20,
offset: Offset(0, 5)
)
],
color: Colors.white,
borderRadius: BorderRadius.circular(30)
),
child: Row(
children: <Widget>[
Align(
alignment: Alignment.center,
child: Padding(
padding: const EdgeInsets.all(5.0),
child: Container(
width: Global.scaleSmallDevice(context) * 64,
height: Global.scaleSmallDevice(context) * 64,
decoration: BoxDecoration(
shape: BoxShape.rectangle,
borderRadius: BorderRadius.circular(10),
image: DecorationImage(
fit: BoxFit.cover,
image: event.image
)
)
),
)
,
),
Flexible(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
CustomText(
text: title,
color: Global.findCategory(event.categId).color,
fontSize: 16,
),
Flexible(
child: CustomText(
text: shortInfo,
color: Global.findCategory(event.categId).color,
fontSize: 12,
),
)
],
),
),
Stack(
alignment: Alignment.bottomCenter,
children: <Widget>[
Align(
alignment: Alignment.bottomCenter,
child: StatefulBuilder(
builder: (context, setState) {
IconData buttonIcon = (event.favorite) ? Icons.favorite : Icons.favorite_border;
return SplashButton(
splashColor: Global.findCategory(event.categId).color,
child: Icon(buttonIcon, color: Global.findCategory(event.categId).color, size: 30),
onTap: () async {
await event.setFavorite(context);
setState(() {
buttonIcon = (event.favorite) ? Icons.favorite : Icons.favorite_border;
});
}
);
},
),
),
],
),
),
],
);
}
In this case I want the StatefulBuilder widget to be on the bottom and the entire container be as small as the column with the CustomText widgets.
The widget with image inside I want it to be centered, while the text to be fully available to the user.
If I don't add a Column as Container, it goes as the height allows it and the StatefulBuilder widget center itself at the bottom, in the curent code it's at the center.....
Sorry if I'm not coherent, it's a bit late and I am tired after coding all day and stuck at this widget for a few hours.

Flutter using wrap_content for TabBarView

in this below code i have Wrap widget into TabBarView and i'm not sure as this widget size, when i use Container with specify height my problem solved, but i miss some layouts which i want to show that with map, how can i resolve this problem? i tested SizedBox.expand but it doesn't any change
Flexible(
child: TabBarView(
children: [
Center(
child: Wrap(
children: feeds.map((feed){
return Container(
width: MediaQuery.of(context).size.width /3.5,
height:MediaQuery.of(context).size.width /3.5,
margin: EdgeInsets.all(2.0),
child: GridTile(
header: feed.feedType ==1?Icon(Icons.video_call)
child: Center(
child: ClipRRect(
borderRadius: BorderRadius.circular(3.0)
child: Image.asset(feed.feedImage))),
),
);
}).toList(),
),
),
],
controller: tabController,
),
),