flutter ImageIcon change size - flutter

I have this ImageIcon:
Container(
color: Colors.yellow,
padding: const EdgeInsets.all(0.0),
child: ImageIcon(AssetImage("assets/images/group.png"), size: 50,))
I get this:
How can I make the icon take all the space available?

Use FittedBox for stretch icon.
Container(
height: 50,
width: 50,
child: FittedBox(
fit: BoxFit.cover,
child: ImageIcon(AssetImage("assets/icon/camera.png"))),)

Related

Flutter: Increase tap area of button (InkResponse)

I have an SVG icon and I struggle to make the tap area of it bigger, without making the icon bigger itself.
The icon is pretty small and so the tap area is small as well. But for UI reasons I do not want to make the icon bigger, is there any solution to increasing the tap area for this?
Here is my code snippet:
Container(
margin: EdgeInsets.only(right: 55),
child: InkResponse(
onTap: () {},
child: SvgPicture.asset("assets/svg/regular/bell.svg",
alignment: Alignment.centerRight, height: 24.w, width: 24.w),
),
)
you can just wrap the SvgPicture with another widget that can expand padding or size.
A better approach is the Padding widget :
Container(
margin: EdgeInsets.only(right: 55.w),
child: InkResponse(
onTap: () {},
child: Padding(
padding: const EdgeInsets.all(10),
child: SvgPicture.asset("assets/svg/regular/bell.svg",
alignment: Alignment.centerRight, height: 24.w, width: 24.w),
),
),
),
or with sizedBox :
Container(
margin: EdgeInsets.only(right: 55.w),
child: InkResponse(
onTap: () {},
child: SizedBox(
width: 100,
height: 100,
child: SvgPicture.asset("assets/svg/regular/bell.svg",
alignment: Alignment.centerRight, height: 24.w, width: 24.w),
),
),
),

Flutter - How to adjust position of an image in a container with fit:boxfit.cover

so i have a container that displays an image, and the image fitted to the container with fit:BoxFit.cover, here is the code:
Container(
width: 80,
height: 80,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
image: DecorationImage(
fit: BoxFit.cover,
image: AssetImage(
"assets/images/MojitoImage.png"),
),
),
),
the result of the code will looks like this
i just want to change the position of the image down a little bit to the bottom, so it can be looks like this (there is a little black space above the leaf)
any solution how to do that?
Try alignment: Alignment.topCenter
You can simply position the image with Stack and Position widget like this:
Container(
color: Colors.grey,
width: 80,
height: 80,
child: Stack(
alignment: AlignmentDirectional.center,
children: <Widget>[
Positioned(
bottom: 10.0,
right: 10,
left: 10,
child: Icon(Icons.receipt,
size: 50.0, color: Colors.greenAccent[400]), //Icon
),
],
),
),

Flutter asset image wont display properly

I want to add an icon to a card widget so I used the ImageIcon widget as below
Card(
color: colorPalette.cultured,
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Row(
children: <Widget>[
Text(label,style: TextStyle(fontWeight: FontWeight.w600,fontSize: 15.0,fontFamily: 'Poppins'),),
Spacer(),
ImageIcon(AssetImage('assets/icons/call.png'),),
],
),
),
);
The icon I want to display is,
but what is displayed is,
the assets in the pubspec.yaml are indented properly as well.
Try below Code Hope its help to you . Just change your image on your need
you have add asset image in 2 Ways
Image.assets() - Documentation here
AssetImage()
Row(
children: [
Image(
image: AssetImage('assets/images/shop.png'),
width: 150,
height: 150,
),
Image.asset(
'assets/images/cycle.png',
width: 150,
height: 150,
),
],
),
Your Result Screen ->
You can use either of these for using asset images
Image.asset('image')
or
Image(image: AssetImage('image')) for using asset images
For achieving it with icon
Container(
width: 40,
height: 40,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.blue),
child: Icon(
Icons.call,
color: Colors.white,
),
)

Can't resize svg picture in flutter

I need to make an svg image size like on the photo below
But when i'm trying to give this size through SvgPicture.asset constructor or with a SizedBox it doesn't make any effect and i'm getting something like this
here is my code of that widget
Container(
width: 80,
height: 80,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
gradient: yellowGradient,
),
child: SizedBox(
height: 29,
width: 45,
child: SvgPicture.asset(
dishIconPath,
color: whiteIconColor,
),
),
),
I think that my Svg picture stretches to container size but i don't know what causes such a behaviour because there is SizedBox
Container doesn't know how to align the child if it is smaller than the container itself, so it expands it to fill the containers size.
The SizedBox can also be removed as SvgPicture.asset(...) now accepts size parameters.
Based on the above information, a possible solution for you will be the following, the important bit being the addition of alignment: Alignment.center:
Container(
width: 80,
height: 80,
alignment: Alignment.center,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
gradient: yellowGradient,
),
child: SvgPicture.asset(
dishIconPath,
color: whiteIconColor,
height: 29,
width: 45,
),
),
For further information, refer to "Layout behaviour" in the Container widget documentation here.
you can use padding or margin
Container(
width: 40,
height: 40,
padding: const EdgeInsets.all(15),
child: SvgPicture.asset(
"assets/icons/outline/edit2.svg",
),
);
Instead of wrapping it with a SizedBox, use the fields height and width of the SvgPicture.
SvgPicture.asset(
dishIconPath,
color: whiteIconColor,
height: 29,
width: 45,
),

Flutter image in SizedBox is overridden by parent Container

I am trying to place an image in the center of a box (container with border). The image size is set by surrounding it with a sized box, the the border or box is being created by surrounding that with a container with box decoration like this:
InkWell(
child: Container(
decoration: BoxDecoration(border: Border.all()),
height: 50,
width: 70,
child: SizedBox(
height: 10,
width: 10,
child: Image.asset('assets/store_physical.png',
fit: BoxFit.cover)),
),
),
The problem is that the image asset it ignoring the dimensions of the sized box and taking the size from the surrounding container making the image too big.
I am not sure why this is happening unless it gets it size from the top of the widget tree which doesn't seem to make sense.
Remove width and height from Container and SizedBox, instead provide it in Image.asset()
Container(
decoration: BoxDecoration(border: Border.all(color: Colors.blue, width: 5)),
child: Image.asset(
'assets/store_physical.png',
fit: BoxFit.cover,
height: 50, // set your height
width: 70, // and width here
),
)
I also had the same problem. You can try adding the Image.asset inside another container and then change the size of that container accordingly.
InkWell(
child: Container(
decoration: BoxDecoration(border: Border.all()),
height: 50,
width: 70,
child: SizedBox(
height: 10,
width: 10,
child: Container(
height: 40.0,
width: 40.0,
child: Image.asset(
'assets/store_physical.png',
fit: BoxFit.cover
)
)
),
),
)
When the child container is smaller than the parent, the parent doesn't know where to place it, so it forces it to have the same size. If you include the parameter alignment in the parent container, it will respect the size of the child Container:
InkWell(
child: Container(
alignment: Alignment.topLeft, //Set it to your specific need
decoration: BoxDecoration(border: Border.all()),
height: 50,
width: 70,
child: SizedBox(
height: 10,
width: 10,
child: Image.asset('assets/store_physical.png',
fit: BoxFit.cover)),
),
),