Flutter: How to erase a part of a widget with another - flutter

In Flutter, how can I add a slightly bigger circle or border at the same position as the green dot, between the grey container and the green dot, and remove the grey container behind it so that the dark blue background is visible?
The goal is to make the green dot or a counter more visible when it overlays the child (grey container).
The grey container can be any widget, that can have a badge. For a container I will just paint with path but here it is really to remove some how a part of the widget (here the grey container, but can be a image or a button ...).
Here is the desired UI:
This is what I have so far:
Stack(
clipBehavior: Clip.none,
children: [
Container(
height: 70,
width: 250,
color: Colors.grey,
),
Positioned(
top: -8,
right: -8,
child: ClipOval(
child: Container(
width: 20,
height: 20,
color: Colors.green,
),
),
)
],
)

You can try something like this:
Wrap your green container with another container & set outer container color same as the color of your background widget.
P.S. I have used blueGrey Color in my Background Widget & also in outer Container
Stack(
clipBehavior: Clip.none,
children: [
Container(
height: 70,
width: 250,
color: Colors.grey,
),
Positioned(
top: -8,
right: -8,
child: ClipOval(
child: Container(
width: 28,
height: 28,
color: Colors.blueGrey,
child: Center(
child: ClipOval(
child: Container(
height: 18,
width: 18,
color: Colors.green,
)))),
),
)
],
)
Output:

Related

two widgets on top of each other

I want to put another widget on the top corner of a container, and I want to put it slightly out of the container as in the picture below.
Use Stack widget and set its clipBehavior to none:
Stack(
clipBehavior: Clip.none, // <--- important part
children: [
Container(
width: 200,
height: 100,
color: Colors.blue,
),
Positioned(
right: -10,
top: -10,
child: Container(
width: 50,
height: 20,
color: Colors.green,
),
),
],
),

Gesture Detector not working having container as child and Positioned as parent

I have a widget tree like:
Stack(
clipBehavior: Clip.none,
children: [
Container(
height: 20,
width: 100,
color: Colors.red,
),
Positioned(
right: -10,
top: -20,
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
print('hello world');
},
child: Container(
decoration: BoxDecoration(
color: Colors.yellow,
borderRadius:
BorderRadius.circular(50.0),
border: Border.all(
color: Theme.of(context)
.scaffoldBackgroundColor,
width: 1.0)),
height: 30,
width: 30,
),
))
],
)
Gesture detector is only working for the region which lies inside the stack boundary (hence which is visible when clipBehavior is Clip.hardEdge,)
How to make the whole Gesture detector work or what could be an alternative approach to stack a clickable widget.
There are a lot of similar questions but I am not able to get the correct approach.
Your GestureDetecture is not working because of the overlapping of the red Container and blue container over each other, I don't know the exact reason
but its woking by removing the red container
or by wrapping the red with Positioned widget also

How to use Align to put widget offscreen (How Alignment(x,y) really works) in Flutter

I try to put a widget offscreen and then create a slide animation to transition inside the screen. I encountered a problem with Align widget which seems to not work as documentation states (Align, Alignment).
I have a Widget (same size as the screen) and I want to position it outside of the screen (on the left side). By their documentation, an Align widget with Alignment(-3, 0) should do the trick but, when I experimented, Align acted very different based on the child size.
I created 3 examples where I have a parent container (which takes place of the screen container) and a child container which represents the widget I want to align.
In #align1 the child moved outside of the parent container but not enough, per their documentation it should be moved by the entire width of the parent widget.
The distance from -1.0 to +1.0 is the distance from one side of the rectangle to the other side of the rectangle. Therefore, 2.0 units horizontally (or vertically) is equivalent to the width (or height) of the rectangle.
In #align2 the child moved very little and in #align3 not 'moved' at all even if the x(-10 or -100) is smaller.
Column(
children: [
// #align1
Container(
margin: EdgeInsets.only(top: 50),
color: Colors.redAccent,
width: 100,
height: 100,
child: Align(
alignment: Alignment(-3, 0),
child: Container(
color: Colors.black,
width: 50,
height: 50,
),
),
),
// #align2
Container(
color: Colors.amberAccent,
width: 100,
height: 100,
child: Align(
alignment: Alignment(-3, 0),
child: Container(
color: Colors.deepPurpleAccent,
width: 90,
height: 50,
),
),
),
// #align3
Container(
color: Colors.greenAccent,
width: 100,
height: 100,
child: Align(
alignment: Alignment(-3, 0),
child: Container(
color: Colors.deepOrange,
width: 100,
height: 50,
),
),
),
],
);
What I understood wrong and how can I accomplish what I want ?

Flutter Container on top of rows

I made a bunch of rows. Now I want a Container on top of these rows. How can I do this. I tried it with the stack widget ,but it just stacked everything on top of each other and I had no control over the positioning.
How can I draw a Container on top of a bunch of rows.
Thank you for your help.
You can check the below code, though your asking is little bit confusing. You need to use Positioned and set some value at top and left.
Scaffold(
body: Stack(
children: [
Positioned(
top:0 ,
left: 0,
child: Container(
height: 100,
width: 100,
color: Colors.red,
),
),
Positioned(
top:100 ,
left: 0,
child: Container(
height: 100,
width: 100,
color: Colors.red,
child: Row(),
),
),
Positioned(
top:200 ,
left: 0,
child: Container(
height: 100,
width: 100,
color: Colors.red,
child: Row(),
),
),
Positioned(
top:300 ,
left: 0,
child: Container(
height: 100,
width: 100,
color: Colors.red,
child: Row(),
),
),
],
),
)

How to fix "Container cuts another container" problem

If I set the height of the green container to MediaQuery.of(context).size.height/2 it's work as expected, But set the height of the green container to MediaQuery.of(context).size.height/3 causes the green container to cut the blue container.
How do I get over this?
Stack(
children: <Widget>[
Container(
height: MediaQuery.of(context).size.height/3,
color: Colors.green,
),
Positioned(
top: 80,
right: 30,
left: 30,
child: Container(
height: 200,
width: 400.0,
))
For some reason the green container is working as the "main screen" and it's positioning the rest of the Stack children into it.
So... I just wrapped the main Container into a Column (I think you could use any multi-child layout) and it works as expected.
body: Stack(
children: <Widget>[
Column(
children: [
Container(
height: MediaQuery.of(context).size.height / 3,
color: Colors.green,
),
],
),
Positioned(
top: 80,
right: 30,
left: 30,
child: Container(
color: Colors.blue,
height: 200,
width: 400.0,
),
),
],
),
);
Hope it helps you.