Scaled Container Overlapping Parent-widget flutter [duplicate] - flutter

This question already has answers here:
Flutter mask a circle into a container
(2 answers)
Closed 2 years ago.
How do I make this blue-circle not overlap the green-box, but insted be confined to the inner bounderyes of the green-box?
Code:
Container(
width: 300,
height: 100,
color: Colors.green,
child: Transform.scale(
scale: 2,
child: Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.blue
),
),
),
),
Pictures tells the rest:
Thx already
- Tobias

I was able to do this using ClipRect widget with hardEdge on clipBehaviour property.
Center(
child: Container(
width: 300,
height: 100,
color: Colors.green,
child: ClipRect(
clipBehavior: Clip.hardEdge,
child: Transform.scale(
scale: 2,
child: Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.blue,
),
),
),
),
),
),

Related

How to overlay widget on widget in flutter [duplicate]

This question already has answers here:
How can I put a widget above another widget in Flutter?
(4 answers)
Closed 6 months ago.
I'd need to build a content widget with the red circle over the text content in Flutter, how can I do?
you can do it using stack widget
return Scaffold(
body: Center(
child: Container(
width: 450,
height: 200,
color: Colors.white,
child: Stack(
children: [
Align(
alignment: Alignment.center,
child: Container(
width: 400,
height: 150,
decoration: BoxDecoration(
color: Colors.blue,
borderRadius:BorderRadius.circular(20)
),
),
),
Align(
alignment: Alignment.topRight,
child: Container(
width: 100,
height: 100,
decoration: BoxDecoration(
color: Colors.red,
shape: BoxShape.circle
),
),
),
],
),
),
),
);

How can I make the outer circles

I am trying to make the display feature for my app, but I am having a hard time making these outer circles, any input is appreciated
There is a way to draw using coordinates.
You can set the ratio using MediaQuery.of(context).size.
return Scaffold(
body: SafeArea(
child: Stack(
children: <Widget>[
Positioned(
top: 200,
left: 80,
child: Container(
width: 200,
height: 200,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(128.0),
border: Border.all(color: Colors.blue),
),
),
),
Positioned(
top: 225,
left: 105,
child: Container(
width: 150,
height: 150,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(128.0),
border: Border.all(color: Colors.blue),
),
),
),
],
),
),
);
Use this:
Container(
color: Colors.white,
child: Center(
child: Container(
width: 200,
height: 200,
decoration: BoxDecoration(
gradient: const LinearGradient(
colors: [Colors.white,Colors.white, Colors.red, Colors.red, Colors.white,Colors.white],
transform: GradientRotation(pi / 2),
),
borderRadius: BorderRadius.circular(128.0),
),
child: Center(
child: Container(
width: 198,
height: 198,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(120.0),
),
),
),
),
),
),
It leads to this output:
use stack widget and put 2 circle containers with different size as children in stack widget

Flutter border radius aspect

Someone knows how to do soft border radius, something like that :
Is it even possible with Flutter, I can't find how.
You can achieve this by using the borderRadius property of the decoration inside a Container.
For example:
Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Container(
height: 200,
width: 200,
decoration: BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.all(Radius.elliptical(20, 10)),
),
),
Container(
height: 200,
width: 200,
decoration: BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.all(Radius.circular(20)),
),
),
],
),
will yield this result
on the other hand, if you want to have a different color for the border, you can try this, setting the color in the border property of the decoration property in the Container:
Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Container(
height: 200,
width: 200,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(20)),
border: Border.all(
color: Colors.red,
),
),
child: Center(
child: Text('Content...'),
),
),
],
),
),
the result for this is
You can use ClipRect.
ClipRRect(
// Change border radius and type(.zero, .roundrect, or absolute values) to get your desired effect
borderRadius: BorderRadius.circular(8.0),
child: Container(color: Colors.grey),
)

Flutter shape overlapping screen width

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

Small container with only one character no centering correctly - Flutter

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('+')
),
);