Move container to the left - flutter

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),),
],
),

Related

Flutter Image not shrinking when window gets smaller

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,
),
),

Height adjustment of an Image in a row inside a Card

my idea is to create a card widget that has an image on the left and corresponding text data on the right side. The picture should always take the full height and 1/3 of the width (I used expanded with flex to get this. Not sure if this is the best way). The image should be placed in a stack in order to stack further widgets.
My problem is that I am not able to place the image in the stack without specifying a fixed height. I tried Positoned.fill but this did not work for me.
This is my code so far for the card:
Widget build(BuildContext context) {
return Card(
elevation: 5,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0),
),
child: Row(
children: [
Expanded(
child: Stack(
children: [
Container(
// child: Positioned.fill(
// child: ClipRRect(
// borderRadius: BorderRadius.circular(15.0),
// child: Image(
// image: AssetImage("assets/eyes.jpg"),
// fit: BoxFit.cover,
// ),
// ),
// ),
),
],
),
),
Expanded(
flex: 2,
child: Container(
color: Colors.grey,
child: Padding(
padding:
const EdgeInsets.symmetric(horizontal: 15.0, vertical: 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text("This is a test"),
SizedBox(height: 10),
Text("This is a test test"),
SizedBox(height: 10),
Text("This is a test test test"),
SizedBox(height: 10),
Text("This is a test test"),
SizedBox(height: 10),
Text("This is a test"),
],
),
),
),
),
],
),
);
}
Here is a picture of the current state. The image should take up the entire white area on the left side of the card.
Instead of adding a child image widget inside your container, you can add a decoration image to the container itself. Here's how you do it:
Container(
decoration: BoxDecoration(
image: DecorationImage(
fit: BoxFit.cover,
image: AssetImage("url"),
),
),
),

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.

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.

Unable to change image size in dart

My image is unable to resize. Firstly I have put the background in the container widget. After that, I have put the logo image in the center widget using Image.assets. The main problem is that the size of the image is resizing according to the height and width. Currently, I am coding in the flutter framework using dart language.
I am doing coding in Android Studio.
#override
Widget build(BuildContext context) {
return new MaterialApp(
debugShowCheckedModeBanner: false,
home: new Scaffold(
body: new Stack(
children: <Widget>[
new Container(
decoration: new BoxDecoration(
image: new DecorationImage(
image: new AssetImage("assets/imgs/home_bg.png"),
fit: BoxFit.cover,
)
),
),
new Center(
child: Image.asset("assets/imgs/home_logo.png",height: 300,width:300,),
)
],
),
),
);
No error messages are showing. Then also the image is not resizing.
body: Center(
child: SizedBox(
width: 100.0,
height: 100.0,
child: Image.network(
"https://th.thgim.com/opinion/op-ed/article22695424.ece/alternates/FREE_300/9thscience"),
),
))
You can use it like-
new Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
new Expanded(child: new Image.asset(
"assets/imgs/home_logo.png",height: 300,width:300,
),
),
]
)
new Container(
height: 20.0,
width: 20.0,
decoration: BoxDecoration(
shape: BoxShape.circle, color: Colors.red),
child: Image.asset(
'assets/Like#3x.png',
)),
You can also try wrapping the Image in a Flexible located in a Column wich is wrapped in a Container with the dimensions you need