I have tried to achieve this widget but nothing is working:
is it possible to create it?
You can try something like this, in case you are trying to put a widget over another.
Container(
width: 100,
margin: EdgeInsets.only(left: 16, right: 16, top: 16),
child: Stack(
children: [
Positioned(
top: 20,
child: Container(
height: 100,
width: 100,
color: Colors.red
)
),
Positioned(
top: 0,
left: 10,
right: 10,
child: Container(
height: 40,
color: Colors.green
)
),
]
),
)
Related
I try on the Back drop Filter in the Flutter widget but get a strange effect. On the one hand there is a blur, on the other hand the objects retain clear boundaries. What am I doing wrong?
child: Stack(
children: <Widget>[
Positioned(
right: 10,
top: 10,
child: Container(
width: 100,
height: 100,
color: Color(0xFFbfeb91),
),
),
Positioned(
bottom: 10,
left: 50,
child: Container(
width: 90,
height: 90,
color: Colors.green,
),
),
Text('Hello world'),
Container(
width: 180,
height: 180,
child: ClipRRect(
borderRadius: BorderRadius.circular(24),
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 10.0, sigmaY: 10.0),
child: Container(
width: 100,
height: 100,
padding: EdgeInsets.all(24),
// color: Color(0xFF55aaff),
color: Colors.white.withOpacity(0.5),
child: Text(
"Flutter Dev's",
style: TextStyle(
fontSize: 28,
fontWeight: FontWeight.bold,
color: Colors.black38,
),
),
),
),
),
),
],
)
I here is what I've got. Look at the green square - its bounds are clear, like we have 2 layers^ one is blured, and the other one (at the top) is NOT blured).
Picture with blur effect
And the same effect with letters 'Hello world'
You should give blur container position by margin as you are using stack as base widget. As you set postioned in above for two widget from top and left. so above two postined overleaped by blur container layout. thats why you getting blur screen. Try below code it will serve your purpose.
Stack(
children: <Widget>[
Positioned(
left: 10,
top: 10,
child: Container(
width: 100,
height: 100,
color: Color(0xFFbfeb91),
),
),
Positioned(
left: 10,
top: 120,
child: Container(
width: 90,
height: 90,
color: Colors.green,
),
),
Text('Hello world'),
Container(
margin: EdgeInsets.only(top: 10, left: 120),
width: 180,
height: 180,
child: ClipRRect(
borderRadius: BorderRadius.circular(24),
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 10.0, sigmaY: 10.0),
child: Container(
width: 100,
height: 100,
padding: EdgeInsets.all(24),
// color: Color(0xFF55aaff),
color: Colors.white.withOpacity(0.5),
child: Text(
"Flutter Dev's",
style: TextStyle(
fontSize: 28,
fontWeight: FontWeight.bold,
color: Colors.black38,
),
),
),
),
),
),
],
);
Container(
padding:
EdgeInsets.only(left: 16, right: 20, top: 16, bottom: 16),
height: 68,
width: 200,
color: Colors.green,
child: Row(
children: [
Expanded(
child: Container(
child: Stack(
children: <Widget>[
Positioned(
// top: 16,
left: 0,
// height: 40,
// width: 40,
child: Container(
height: 36,
width: 60,
decoration: BoxDecoration(
color: Colors.black,
shape: BoxShape.circle,
),
),
),
],
),
),
),
SizedBox(
width: 4,
),
Container(
width: 120,
height: 30,
color: Colors.red,
),
],
),
)
The black circle is wrapped by Expanded
But the space is invaded by others
how to prevent this??
I'd rather this give overflow to the right without clipping my stack widget.
You can use Positioned in a container instead of circle.
Container(
padding: EdgeInsets.only(left: 16, right: 20, top: 16, bottom: 16),
height: 68,
width: double.infinity,
color: Colors.green,
child: Stack(
children: [
Container(
height: 36,
width: 60,
decoration: BoxDecoration(
color: Colors.black,
shape: BoxShape.circle,
),
),
Positioned(
left: 50,
top: 3,
child: Container(
width: MediaQuery.of(context).size.width-100,
height: 30,
color: Colors.red,
),
),
],
),
)
Output:
I am using a stack to arrange images in a circle, with slight overlap. But I want the green icon to overlap the grey icon, while maintaining the other overlapping order. Basically I want each icon to be only partially obscured. Please see attached image and code.
Stack(
children: [
Positioned(
bottom: 3,
left: 0,
child: SvgPicture.asset(
'images/elem_earth.svg',
width: 15,
),
),
Positioned(
top: 3,
left: 0,
child: SvgPicture.asset(
'images/elem_dark.svg',
width: 15,
),
),
Positioned(
top: 0,
left: 0,
right: 0,
child: SvgPicture.asset(
'images/elem_light.svg',
width: 15,
),
),
Positioned(
top: 3,
right: 0,
child: SvgPicture.asset(
'images/elem_fire.svg',
width: 15,
),
),
Positioned(
bottom: 3,
right: 0,
child: SvgPicture.asset(
'images/elem_ice.svg',
width: 15,
),
),
Positioned(
bottom: 0,
left: 0,
right: 0,
child: SvgPicture.asset(
'images/elem_air.svg',
width: 15,
),
),
],
)
How put orange container full width?
I'm try with double.infinity but get error BoxConstraints forces an infinite width.
Container(
padding: EdgeInsets.symmetric(horizontal: 20),
height: 205,
color: Colors.grey,
//margin: EdgeInsets.symmetric(vertical: 20),
child: Stack(
children: [
Positioned(
left: 0,
bottom: 0,
child: Container(
height: 185,
width: 350, //double.infinity --not working
color: Colors.deepOrange,
),
),
Positioned(
right:0,
top:0,
child: Image.asset('assets/images/book-1.png',width: 150,),
),
],
),
)
You can use MediaQuery.of(context).size.width for full screen width of Container widget.
I am using the below code to set the background color as black to the container, but it's not showing.
Align(
alignment: Alignment.bottomCenter,
child: Container(
color: Colors.black,
margin: EdgeInsets.only(left: 20, right: 20, bottom: 20, top: 10),
height: 40,
width: double.infinity,
child: RaisedButton(
textColor: Colors.white,
color: Colors.blue[300],
onPressed: () => null,
child: Text('Next'),
),
),
)
Output:
Can somebody please help me?
Easy solution: Wrap it inside container and give it color property.
Container(
color: Colors.black,
child: Align(
alignment: Alignment.bottomCenter,
child: Container(
margin: EdgeInsets.only(left: 20, right: 20, bottom: 20, top: 10),
height: 40,
width: double.infinity,
child: RaisedButton(
textColor: Colors.white,
color: Colors.blue[300],
onPressed: () => null,
child: Text('Next'),
),
),
),
)
I think the problem is that the RaisedButton gets the size of the Container and that's why you are not seeing any black colour. As NetanZaf suggested, You can use a padding so RaisedButton will not get the container size and you will see a black colour.
This is the result of the following code:
Align(
alignment: Alignment.bottomCenter,
child: Container(
color: Colors.black,
margin: EdgeInsets.only(left: 20, right: 20, bottom: 20, top: 10),
padding : EdgeInsets.only(left: 10, right: 10, bottom: 10, top: 10),
height: 40,
width: double.infinity,
child: RaisedButton(
textColor: Colors.white,
color:Colors.blue[300],
onPressed: () => null,
child: Text('Next'),
),
),
),
You can change the values to get the result you want
Use the padding property instead of margin.