Flutter - BoxConstraints forces an infinite width - flutter

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.

Related

Clip Container in Flutter

I want to clip a container in such a way like below image
I have read about a couple of clip but don't know how to achieve this.
I have tried implementing clipping using..
Container(
width: 300,
height: 300,
color: Colors.white,
child: ClipRRect(
child: Stack(
///clipBehavior: Clip.hardEdge,
children: [
Positioned(
left: 0,
top: 0,
child: Transform.rotate(
angle: 1,
child: Container(
color: Colors.red,
width: 250,
height: 250,
),
),
),
],
),
),
);
I have found a way to do this using CustomClipper

Strange blur in FLutter BackdropFilter

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

Make two widgets aligned to top center Flutter

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

flutter: top of image deleted in stack widget

I am trying to use stack in my widget tree:
body: Center(
child: SingleChildScrollView(
child: Stack(
overflow: Overflow.visible,
children: <Widget>[
Container(
// card view
alignment: Alignment.center,
height: 200,
margin: EdgeInsets.only(
top: 20.0, bottom: 50.0, left: 50.0, right: 50.0),
decoration: BoxDecoration(
color: color_transparent_black,
borderRadius: BorderRadius.circular(14.0),
),
),
Positioned(
top: -60,
left: 0,
right: 0,
bottom: 0,
child: Align(
alignment: Alignment.topCenter,
child: Container(
width: width * 0.3,
height: height * 0.2,
child: CircleAvatar(
backgroundColor: Colors.transparent,
child: Image.asset("assets/images/ic_setting.png"),
),
),
),
),
],
),
),
),
);
And this result is this:
Why top of setting icon has been deleted?
I fixed the problem:
body: Center(
child: SingleChildScrollView(
child: Stack(
// overflow: Overflow.visible,
children: <Widget>[
Container(
// card view
alignment: Alignment.center,
height: 200,
margin: EdgeInsets.only(
top: 80.0, bottom: 50.0, left: 50.0, right: 50.0),
decoration: BoxDecoration(
color: color_transparent_black,
borderRadius: BorderRadius.circular(14.0),
),
),
FractionalTranslation(
translation: Offset(0.0, 0.0),
child: Align(
alignment: Alignment.topCenter,
child: Container(
width: width * 0.3,
height: height * 0.2,
child: CircleAvatar(
backgroundColor: Colors.transparent,
child: Image.asset("assets/images/ic_setting.png"),
),
),
),
),
],
),
),
),
);
and it is result:
I increases Top margin to top: 80.0 and replace Positioned with FractionalTranslation. Actually it works with Positioned too.
Its most likely because you set the top: -60 for the Positioned widget.
Edit 1:
Stop clipping by removing SingleChildScrollView
And you can center all children of Stack using alignment: Alignment.topCenter property of Stack widget itself.
child: Center(
child: Stack(
overflow: Overflow.visible,
alignment: Alignment.topCenter,
children: <Widget>[
Container(
height: 200,
...
),
Positioned(
top: -60,
...
child: Container(
...
),
),
),
]),

Flutter set maxWidth on Stack with constrainedBox

in my simple implementation of Card don't have maxWidth and when i rotate application that fills the width and i'm trying to avoiding that and setting `maxWith:300.0', my code doesn't work
return Container(
color: Color(0xffeeeeee),
child: ConstrainedBox(
constraints: BoxConstraints(maxWidth: 300),
child: Stack(
overflow: Overflow.visible,
children: <Widget>[
Container(
height: 200.0,
color: Colors.indigo,
),
Positioned(
width: MediaQuery.of(context).size.width - 20,
height: MediaQuery.of(context).size.height / 1.3,
left: 10.0,
top: 95.0,
child: Card(
elevation: 2.0,
color: Colors.white,
child: Container(
decoration: BoxDecoration(color: Colors.white12),
),
)),
],
),
));