I want to add a border color around an oval shaped image that doesn't have a constant height value.
My code example:
Align(
child: ConstrainedBox(
constraints: const BoxConstraints(
maxHeight: 220.0,
),
child: Container(
height: null,
width: 150.0,
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(
color: Colors.blueAccent,
width: 2.0,
),
),
child: ClipOval(
child: Image.network(
'https://images.unsplash.com/photo-1606122017369-d782bbb78f32?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxzZWFyY2h8NHx8cG9ydHJhaXRzfGVufDB8fDB8fA%3D%3D&w=1000&q=80',
),
),
),
),
),
This is the result of having a border shape: BoxShape.circle:
and this is the result without any border shape at all
However I want the border to be properly and evenly around the corners of the image.
The only attribute left is boxshape.value but I cant find examples on how to use it. Also the container has a null value, making it harder to insert specific value
Try this:
ClipOval(
child: Container(
height: 150.0,
width: 150.0,
color: Colors.blueAccent,
padding: const EdgeInsets.all(2),
child: ClipOval(
child: Image.network(
fit:BoxFit.cover,
'https://images.unsplash.com/photo-1606122017369-d782bbb78f32?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxzZWFyY2h8NHx8cG9ydHJhaXRzfGVufDB8fDB8fA%3D%3D&w=1000&q=80',
),
),
),
)
Related
I am trying to put Container color as Stack above circle avatar but the problem is that color go out the circle borer
I have the following code,
IntrinsicWidth(
child: Stack(
alignment: Alignment.bottomCenter,
children: [
const CircleAvatar(
radius: 50,
),
Container(
color: Colors.yellowAccent,
height: 30,
)
],
),
)
I get the following output
But I need the output looks like following
How Can I prevent my color from expanding to the circle width
thanks
try this:
CircleAvatar(
backgroundColor: Colors.yellow,
radius: 100,
child: Container(
alignment: Alignment.bottomCenter,
clipBehavior: Clip.antiAlias,
decoration: BoxDecoration(shape: BoxShape.circle),
child: Container(
height: 40,
width: double.infinity,
color: Colors.red,
),
),
)
Where should the red oval be
Hello, my question is how can I get the red oval in the picture above to the position marked below? Does anyone know? I thank you in advance.
This is my code:
return Scaffold(
backgroundColor: const Color(0xffffffff),
body: Stack(
children: <Widget>[
Container(
child: Align(
alignment: Alignment.bottomCenter,
),
width: 436.0,
height: 207.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(29.0),
image: DecorationImage(
image: const AssetImage('assets/images/vorlage.png'),
fit: BoxFit.cover,
),
),
),
Container(
child: Align(
alignment: Alignment.bottomCenter,
),
width: 265.0,
height: 20.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(14.0),
color: const Color(0xffff0000),
),
),
You might need to look into painting a Canvas. It's fairly well developed, and quite a bit of tutorial information on it (even how to animate things!). Everything is a widget, but some of those widgets are RenderObjects. :)
If you want to red oval to always be fixed at a position in it's parent widget, you can use Positioned widget to fix the distance from top, then use Center to place it in the middle. You will have to tweak the top value (I put 300 arbitrarily).
return Scaffold(
backgroundColor: const Color(0xffffffff),
body: Stack(
children: <Widget>[
Container(
child: Align(
alignment: Alignment.bottomCenter,
),
width: 436.0,
height: 207.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(29.0),
image: DecorationImage(
image: const AssetImage('assets/images/vorlage.png'),
fit: BoxFit.cover,
),
),
),
Positioned(
top: 300 // <----tweak this till it's where you want it (distance from top)
child: Center(
child: Container(
child: Align(
alignment: Alignment.bottomCenter,
),
width: 265.0,
height: 20.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(14.0),
color: const Color(0xffff0000),
),
),
),
),
How can I make a shape (or any widget for that matter) overlap the sides of the phone-screen?
I've attached an image that showes what I mean.
Here's my code so far:
Container(
width: 900.0,
height: 900.0,
decoration: new BoxDecoration(
color: Colors.orange,
shape: BoxShape.circle,
),
),
And no, I it doesn't help to increse the size to say 1000, it just stays the same
I just modified the answer.
Transform.scale(
scale: 1.4,
child: Center(
child: Container(
width: 900.0,
height: 900.0,
decoration: new BoxDecoration(
color: Colors.orange,
shape: BoxShape.circle,
),
),
),
)
Add a Transform widget with a proper scale property and remove the height and width in the Container.
Transform.scale(
scale: 1.7,
child: Container(
decoration: new BoxDecoration(
color: Colors.orange,
shape: BoxShape.circle,
),
),
)
I'm trying to add border radius to my container but can't get it to work for me.
Container(
color: ColorPallete.secondColor[50],
height: 400.0,
width: 500.0,
padding: const EdgeInsets.all(10.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10.0),
),
child: SvgPicture.asset(
'assets/images/svg/megacategory/art__grocery.svg',
),
),
the error that you are receiving is that whenever you have a decoration for a container you need to make sure that color parameter is in the decoration instead of just the container. Below I have changed your code to not produce that error message, if you are still having issues getting the border radius to work after this change let me know!
Container(
height: 400.0,
width: 500.0,
padding: const EdgeInsets.all(10.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10.0),
color: ColorPallete.secondColor[50],
),
child: SvgPicture.asset(
'assets/images/svg/megacategory/art__grocery.svg',
),
),
If you have decoration property in the container, you are supposed to pass the color within the decoration and not the container directly.
Container(
//Not allowed color: ColorPallete.secondColor[50],
height: 400.0,
width: 500.0,
padding: const EdgeInsets.all(10.0),
decoration: BoxDecoration(
color: ColorPallete.secondColor[50], //place it here
borderRadius: BorderRadius.circular(10.0),
),
child: SvgPicture.asset(
'assets/images/svg/megacategory/art__grocery.svg',
),
),
Container(
height: 200.0,
width: 300.0,
padding: const EdgeInsets.all(10.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10.0),
color: Colors.green[50],
),
child: AssetImage(
'assets/images/index.png',
),
),
Small container with only one character no centering correctly, with or without padding setted to 0.
If I reduce the font size will render centered, but with default text size no
Container(
decoration: BoxDecoration(
color: Colors.green,
shape: BoxShape.circle,
),
width: 20.0,
height: 20.0,
alignment: Alignment.center,
padding: EdgeInsets.all(0.0),
child: Text(
'+',
),
)
Update:
With icon instead letter behave exact same.
If I change the size from 20 to 40:
Code
Container(
width: 40,
height: 40,
alignment: Alignment.center,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.grey,
),
child: RotatedBox(
quarterTurns: 3,
child: Icon(
Icons.expand_less,
color: Colors.white,
),
),
),
Update 2: With Fitted works with icon:
Container(
width: 20,
height: 20,
alignment: Alignment.center,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Theme.of(context).textTheme.caption.color,
),
child: FittedBox(
child: RotatedBox(
quarterTurns: 3,
child: Icon(
Icons.expand_less,
color: Theme.of(context).primaryColor,
),
),
),
),
I can not reproduce this. But I assume that your default font size is too large for the container. You can try to wrap the Text in a FittedBox, so it will adapt to the container:
return Container(
decoration: BoxDecoration(
color: Colors.green,
shape: BoxShape.circle,
),
width: 20.0,
height: 20.0,
alignment: Alignment.center,
padding: EdgeInsets.all(0.0),
child: FittedBox(
child:Text('+')
),
);