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.
Related
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:
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,
),
),
],
),
SingleChildScrollView(
child: Column(
children: [
Container(
height: 200.0,
width: double.infinity,
color: myBlue.withOpacity(.6),
child: TopCarouselSlider(bgColor: null),
),
//
Container(
height: MediaQuery.of(context).size.width * 1,
width: MediaQuery.of(context).size.width * 0.90,
color: myBlue.withOpacity(.5),
//
child: GridView.count(
mainAxisSpacing: 8,
crossAxisSpacing: 8,
crossAxisCount: 2,
children: [
Container(
height: 200.0,
width: 150.0,
color: myAccent,
),
Container(
height: 150.0,
width: 150.0,
color: myAccent,
),
Container(
height: 150.0,
width: 150.0,
color: myAccent,
),
Container(
height: 150.0,
width: 150.0,
color: myAccent,
)
],
),
),
],
),
),
Issue: If I try to scroll the page with the slide gesture inside the GridView area I don't get the scroll effect. Is this means that inside SingleChildScrollView the usual effects scroll for Grid or List will not work?
Please note I tried with GridView.Builder too, but the same result. Cannot figure a solution!
Thanks in advance for your help
you can do that using NestedScrollView or CustomScrollView, and it will work with sliverGrid and SliverList, but the problem is you can't add normal RenderBox widget like Container be the parent of the Slivers,
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(),
),
),
],
),
)
Is something wrong with this snippet? The positioned element isn't showing up but the others are. deviceHeight is defined elsewhere as the height of the device.
The first container holds the other two containers under it. The second container appears at the top correctly, but the third one (positioned) which should be under the second one doesn't appear. Welcome to hear any alternatives.
Align(
alignment: Alignment.bottomCenter,
child: Stack(children: <Widget>[
Container(
color: Color(bgDark),
height: deviceHeight / 100 * 40,
),
Container(color: Colors.red, height: deviceHeight / 18),
Positioned(
top: 50,
child: Container(
color: Colors.green, height: deviceHeight / 1))
]))
Adding a width to the Positioned Container made it visible.
Align(
alignment: Alignment.bottomCenter,
child: Stack(
children: <Widget>[
Container(
color: Colors.blue,
height: 300,
),
Container(
color: Colors.red,
height: 200,
),
Positioned(
top: 50,
child: Container(
color: Colors.green,
height: 100,
width:100,
),
),
],
),
);
I am not sure about the exact cause of the issue but it seems Positioned needed both height and width dimensions.