Images inside Container not fitting completely - flutter

I have a Container with a Row inside.
Container(
width: MediaQuery.of(context).size.width,
child: Row(
mainAxisAlignment:
MainAxisAlignment.center,
children: [
//mbx
Container(
width: 40.0,
height: 40.0,
decoration: new BoxDecoration(
color: AppColors.grisMovMap,
shape: BoxShape.circle,
image: new DecorationImage(
fit: BoxFit.fill,
image: AssetImage(
'assets/sports/MBX.png')))),
SizedBox(
width: 5,
),
//motocross
Container(
width: 40.0,
height: 40.0,
decoration: new BoxDecoration(
color: AppColors.grisMovMap,
shape: BoxShape.circle,
image: new DecorationImage(
fit: BoxFit.fill,
image: AssetImage(
'assets/sports/motocross.png')))),
],
),
)
The Row contains two other Containers with a circular asset image inside.
The issue is that both image are not filling the circle space, they are cut on some parts of the border.
I would like to put both images completely inside the circles, just as adding a padding value.
EDIT:
Here you have both full images to compare with the app output:

CircleAvatar(
radius: 100,
child: Padding(
padding: EdgeInsets.all(10),
child: Image.asset(
"assets/images/w3lk3.png",
),
),
backgroundColor: Colors.purple,
),
Output:

Use fit:BoxFit.contain to fit the image fully inside the container.

Since you are using circle image I would suggest using the native flutter solution for circle images as found here in the official documentation. https://api.flutter.dev/flutter/material/CircleAvatar-class.html
In terms of code:
CircleAvatar(
backgroundImage: NetworkImage(userAvatarUrl),
)
If I understood correctly you want a certain color around the circle?
Use double CircleAvatar widget. It may not be the correct way but it accomplishes the task.
CircleAvatar(
radius: 70,
backgroundColor: Colors.red,
child: CircleAvatar(
backgroundImage:
AssetImage('assets/sports/motocross.png'),
radius: 50,
),
),
Since it creates two circles just make sure the first one is bigger than the second one and set the color of your choice.

Related

Taking a picture and displaying it effect in flutter

goal: display an image picked inside a circle.
issue: the image picked is clipped on the sides.
Here is the one that I am using to display the image:
CircleAvatar(
radius: 50.0,
child: ClipRRect(
borderRadius: BorderRadius.circular(100),
child: Image.file(_photo!,
width: 100, height: 100, fit: BoxFit.fitHeight),
),
)
the code above is used to display the image after I take a picture from the phone
this is what it looks like
The image should look like this ::
this is the code snip for when the image is being displayed correctly:
Widget _buildProfileImage() => CachedNetworkImage(
imageUrl: _cloudUser.userImage,
imageBuilder: (context, imageProvider) => CircleAvatar(
backgroundColor: Colors.grey.shade800,
radius: 50,
backgroundImage: NetworkImage(_cloudUser.userImage),
),
);
the code above is used to display the image that was stored on firebase
I am pretty sure that the issue is with the widget 'ClipRRect' but I dont know what other widget I can use. or maybe thats not the issue at all idk.
use FittedBox widget
Change this:
CircleAvatar(
radius: 50.0,
child: ClipRRect(
borderRadius: BorderRadius.circular(100),
child: Image.file(_photo!,
width: 100, height: 100, fit: BoxFit.fitHeight),
),
)
to this code below:
ClipRRect(
borderRadius: BorderRadius.circular(100),
child: FittedBox(
alignment: Alignment.center,
fit: BoxFit.cover,
child: Image.file(_photo!)),
),
),

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

How to create a circular image without distortion in flutter

I need to create a circular image but when it is displayed in the container I use the photo is deformed and it shows very badly
Use this code
Container(
height: 100,
width: 100,
decoration: BoxDecoration(
border: Border.all(color: Colors.blueAccent),
borderRadius: BorderRadius.circular(50),
image: DecorationImage(
image: FileImage(photoImage),
fit: BoxFit.fill,
),
),
)
I also provided this code
CircleAvatar(
radius: 40,
child: ClipOval(
child: Image(
height: 100,
fit: BoxFit.fill,
image: FileImage(photoImage),
),
),
)
I appreciate your help with this.
By very badly, I assume you're referring to the distorted aspect ratio of the image. You might want to use BoxFit.cover. BoxFit.fill is known to distort the image's aspect ratio as per the documentation
BoxFit.cover ,on the other hand maintains the aspect ratio while being small as possible.
I suggest use Circle avatar it is better
For asset images
CircleAvatar(backgroundImage: FileImage(photoImage), radius: 55.0)
CircleAvatar With network image
CircleAvatar(
backgroundImage:
NetworkImage('https://www.woolha.com/media/2020/03/eevee.png'),
minRadius: 50,
maxRadius: 75,
)

RectangleBox In Flutter

In my code, there is this CircleAvtar which I want to replace it with a big rectangular box. I am new to flutter I am finding it difficult to achieve this.
child: Card(
elevation: 3,
shape:
RoundedRectangleBorder(borderRadius: BorderRadius.circular(15)),
child: Container(
margin: EdgeInsets.all(5),
padding: EdgeInsets.all(5),
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(
10,
),
// border: Border.all(width: 0.5),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(5)),
color: whiteColor,
),
child: expertiseSearchModel.userImageURL.isEmpty
? CircleAvatar(
radius: 35,
child: SvgPicture.asset(
'assets/images/default_user_image.svg',
// height: screenUtil.setSp(80),
// width: screenUtil.setSp(80),
fit: BoxFit.contain,
),
)
: CircleAvatar(
radius: 35,
backgroundImage:
NetworkImage(expertiseSearchModel.userImageURL),
),
),
I want it to look like this :
If you can show us what your current code is giving the output maybe I can help you more. But As far as i understood this, you can simple use Image.Network() to show the image and remove the circular avatar
Try this, if it works if not lemme know I will edit it accordingly
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(5)),
color: whiteColor,
),
child: expertiseSearchModel.userImageURL.isEmpty
? CircleAvatar(
radius: 35,
child: SvgPicture.asset(
'assets/images/default_user_image.svg',
// height: screenUtil.setSp(80),
// width: screenUtil.setSp(80),
fit: BoxFit.contain,
),
)
: Image.network(expertiseSearchModel.userImageURL)
),
Inside your main container use the column as a child and put another container as a child and use the Image decoration property of the container to display pictures. You can change the border-radius of the child container to have those circular edges.

How to overlay a widget in Flutter with another widget, opacity set to multiply?

This is what I want to achieve:
I know that there's a colorBlendMode on the image widget, but it doesn't allow me to color a part of the image, just the whole. Is it possible to overlay color for a percentage of the image?
For color overlay, you could simply use Container with color that has opacity. Then if you put your image and Container in Stack you could get same result as you have.
EDIT:
If you want to use multiply blending only option that comes to my mind is take two picture one with colorFiler, second(cutted in half) without and put them together. But it's definitely not clean or somehow nice solution.
Code for similar result as your image:
Column(children: <Widget>[
Stack(children: <Widget>[
Image(
image: NetworkImage('https://picsum.photos/600?image=9'),
colorBlendMode: BlendMode.multiply,
color: Colors.green),
AspectRatio(
aspectRatio: 2 / 1,
child: new Container(
decoration: new BoxDecoration(
image: new DecorationImage(
fit: BoxFit.fitWidth,
alignment: FractionalOffset.topCenter,
image: NetworkImage(
'https://picsum.photos/600?image=9',
))))),
]),
Stack(children: <Widget>[
Image(
image: NetworkImage(
'https://www.solidbackgrounds.com/images/1920x1080/1920x1080-white-solid-color-background.jpg'),
height: 100,
fit: BoxFit.fitWidth,
width: MediaQuery.of(context).size.width,
colorBlendMode: BlendMode.multiply,
color: Colors.green),
Center(
child: Text('5',
textAlign: TextAlign.center,
style: TextStyle(color: Colors.white, fontSize: 40)))
])
])
I would definitely consider looking into the Stack Widget, which allows you to overlay children on top of one another. You could have your base image on the bottom, and that filter just above it.