I'm trying to reproduce this layout button
I created a Stack with a Container and a Positioned button, but I can't set the button out of the box.
Stack(children: <Widget>[
Container(
decoration: new BoxDecoration(
shape: BoxShape.rectangle,
border: new Border.all(
color: Colors.black,
width: 1
)
),
child: Text("League of legends")
),
Positioned(
right: 0,
bottom: 0,
child: Container(
width: 9,
height: 9,
child: new Container(
width: 9,
height: 9,
decoration: new BoxDecoration(
color: Colors.white,
shape: BoxShape.circle,
),
),
)
)
])
I tried add Padding but without success.
The result of my code is this:
The constructor of Stack has the overflow argument, which enables you to choose whether to paint its children outside of its boundary.
By passing in Overflow.visible to overflow and setting negative values in right and bottom in Positioned(), you can make the circle stick out of the box.
Stack(
overflow: Overflow.visible,
children: <Widget>[
Container(
decoration: ...,
child: ...,
),
Positioned(
right: -4,
bottom: -4,
child: Container(
width: 9,
height: 9,
decoration: new BoxDecoration(
color: Colors.white,
shape: BoxShape.circle,
),
),
)
],
)
I've reduced redundantly nested Containers into one.
Related
I generated dynamic color from images and make it background color.
I want soft edges of background image and color. How do I implement it?
Container(
decoration: BoxDecoration(
color: Colors.blueAccent,
border: Border.all(
width: 0.5,
),
borderRadius: BorderRadius.all(
Radius.circular(24),
),
),
child: Stack(
children: [
Positioned.fill(child: ProductImageWidget()),
Positioned(
bottom: 0,
left: 0,
right: 0,
child: ProductNameWidget(),
)
],
),
);
Use ClipRRect
ClipRRect(
borderRadius: BorderRadius.circular(8.0),
child: Image.network(
"src",
height: 150.0,
width: 100.0,
),
)
wrap your ProductImageWidget() with ClipRReact. Where there is a property called borderRadius.
ClipRRect(
borderRadius: BorderRadius.circular(8.0),
child: ProductImageWidget(),
)
Or you can use this widget in the inner code of ProductImageWidget() as a parent widget
You will need a ClipRRect and a BackDropFilter to get the effect that you want. By the way this effect is called frosted glass, you can find many info about it. Let me show you an example (I not tested it :) ).
ClipRRect(
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 3, sigmaY: 3),
child: Container(
decoration: BoxDecoration(
color: Colors.blueAccent,
border: Border.all(
width: 0.5,
),
borderRadius: BorderRadius.all(
Radius.circular(24),
),
),
child: Stack(
children: [
Positioned.fill(child: ProductImageWidget()),
Positioned(
bottom: 0,
left: 0,
right: 0,
child: ProductNameWidget(),
)
],
),
);
),
),
Hope you all are doing well. I am making a flutter application. In this interface I am having a issue. I am making a container and circle avatar which are in stack. In stack, in first widget container there is also another container. When I set image as a child to inner container it also applied to outer container. Why is this happening and what is the solution of this problem.
Stack(
children: [
// Container(child:
Container(
decoration: BoxDecoration(
border: Border.all(
color: Colors.indigo,
)),
width: 340,
height: 200,
child: Container(
child: Image.asset(
'assets/pic1.jpg',
fit: BoxFit.cover,
),
width: 340,
height: 150,
decoration: BoxDecoration(
border: Border.all(
color: Colors.black,
)),
),
),
Positioned(
bottom: 10,
right: 10,
child: CircleAvatar(
backgroundColor: Colors.grey,
radius: 40,
))
],
)
I think You just need to Alignment Property to your Parent widget otherwise child widget will not care about height and width
Stack(
children: [
// Container(child:
Container(
alignment: Alignment.center,
decoration: BoxDecoration(
border: Border.all(
color: Colors.indigo,
)),
width: 340,
height: 200,
child: Container(
child: Image.asset(
'assets/pic1.jpg',
fit: BoxFit.cover,
),
width: 340,
height: 150,
decoration: BoxDecoration(
border: Border.all(
color: Colors.black,
)),
),
),
Positioned(
bottom: 10,
right: 10,
child: CircleAvatar(
backgroundColor: Colors.grey,
radius: 40,
))
],
)
You can also follow the below article to get more information.
https://www.kindacode.com/article/flutter-sizing-a-container-inside-another-container/#:~:text=To%20size%20a%20Container%20that,expand%20to%20its%20parent's%20constraints.
I want to add two boxes, one inside another. Here's my code and its not working for two boxes. how should I correct this. doc UI in this doc you can see the UI I implement so far and the UI I want to be implement.
Widget DetailBox() => Padding(
padding: const EdgeInsets.only(left: 25, right: 25),
child:Column(
children: [
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30.0),
color: Colors.white,
),
// alignment: Alignment.bottomCenter,
height: 400,
width: 300,
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30.0),
color: Colors.lightBlue,
),
// alignment: Alignment.bottomCenter,
height: 100,
width: 300,
),
),
],
),
);
May it help you
Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(25),
),
elevation: 5,
shadowColor: Colors.blue.shade200,
child: Column(
children: [
Expanded(
flex: 1,
child: Container(
decoration: BoxDecoration(
color: Colors.lightBlueAccent,
borderRadius: BorderRadius.only(topLeft:Radius.circular(25),topRight:Radius.circular(25))
),
),
),
Expanded(
flex: 3,
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(bottomRight:Radius.circular(25),bottomLeft:Radius.circular(25))
),
),
)
],
),
),
According to the design of the app, put the image in the bule box.
i want to add another MaterialButton under the first one.
I got the first Button and a want to add multiple ones.
body: SingleChildScrollView(
child: Padding(
padding: EdgeInsets.only(top: 15, bottom: 0, left: 5, right: 5),
child: MaterialButton(
onPressed: () {},
child: Container(
height: 180,
width: double.infinity,
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius: BorderRadius.circular(20.0),
),),)
You can create the buttons inside the Expanded widget to allocate space evenly within a Row
body: return SingleChildScrollView (
child: Padding(
padding: EdgeInsets.only(top: 15, bottom: 0, left: 5, right: 5),
child: Row(
children: [
Expanded(
child: MaterialButton(
onPressed: () {},
child: Container(
height: 180,
width: double.infinity,
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius: BorderRadius.circular(20.0),
),
)
),
),
Expanded(
child: MaterialButton(
onPressed: () {},
child: Container(
height: 180,
width: double.infinity,
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius: BorderRadius.circular(20.0),
),
)
),
),
Expanded(
child: MaterialButton(
onPressed: () {},
child: Container(
height: 180,
width: double.infinity,
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius: BorderRadius.circular(20.0),
),
)
),
),
],
),
)
);
If you want to Add Multiple Buttons and if you want to align them horizontally, then enclose the buttons inside a Row Widget. If you want to Align them Vertically, Enclose them inside a Column Widget.
If you want to have both Horizontally and Vertically aligned Make the Parent Widget as Column and have multiple children of Row Widgets and The Row can have Buttons as children
Container(
// decoration: BoxDecoration(
// border: Border.all(color: Colors.black45),
// borderRadius: BorderRadius.circular(8.0),
// ),
child: Row(
children: <Widget>[
Container(
child: Text("hi"),
margin : EdgeInsets.fromLTRB(20, 8, 8, 16),
width: MediaQuery.of(context).size.width *0.42,
height: 90,
color: Colors.black12,
),
Container(
child: Text("Hi"),
margin: EdgeInsets.fromLTRB(16, 8, 8, 16),
width: MediaQuery.of(context).size.width * 0.42 ,
height: 90,
color: Colors.black12,
)
],
),
),
I can add border using Box decoration on the outer container, but it's throwing me an error when I am trying to do the same on the inner containers. What is the problem and how to solve it?
In order to add border on container inside row widget , we have to use decoration for the inner containers.
Once you will post the error, we can answer you better but i think the below code will be helpful for you.
If you are using decoration then you must not add colour attribute in container directly, it should be in decoration only.
Container(
child: Row(
children: <Widget>[
Container(
child: Text("hi"),
margin: EdgeInsets.fromLTRB(20, 8, 8, 16),
width: MediaQuery.of(context).size.width * 0.42,
height: 90,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(4)),
shape: BoxShape.rectangle,
border: Border.all(
color: Colors.blue,
width: 4,
)),
),
Container(
child: Text("Hi"),
margin: EdgeInsets.fromLTRB(16, 8, 8, 16),
width: MediaQuery.of(context).size.width * 0.42,
height: 90,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(4)),
shape: BoxShape.rectangle,
border: Border.all(
color: Colors.blue,
width: 4,
)),
)
],
),
),
In container widgets you cannot use the color and decoration at the same time. Remove the color property from the Container and move it into the BoxDecoration widget
This should work:
Container(
child: Row(
children: <Widget>[
Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.black45),
borderRadius: BorderRadius.circular(8.0),
color: Colors.black12, //add it here
),
child: Text("hi"),
margin : EdgeInsets.fromLTRB(20, 8, 8, 16),
width: MediaQuery.of(context).size.width *0.42,
height: 90,
//color: Colors.black12, //must be removed
),
Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.black45),
borderRadius: BorderRadius.circular(8.0),
color: Colors.black12, //add it here
),
child: Text("Hi"),
margin: EdgeInsets.fromLTRB(16, 8, 8, 16),
width: MediaQuery.of(context).size.width * 0.42 ,
height: 90,
//color: Colors.black12, // must be removed
)
],
),
),
Consider the humble Divider widget to keep things simple. If you add it to the bottom of a Column in your row it will add a line that will act as a border.
const Divider(height: 1.0,),