Flutter container inside a container using a widget - flutter

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.

Related

How can I make the outer circles

I am trying to make the display feature for my app, but I am having a hard time making these outer circles, any input is appreciated
There is a way to draw using coordinates.
You can set the ratio using MediaQuery.of(context).size.
return Scaffold(
body: SafeArea(
child: Stack(
children: <Widget>[
Positioned(
top: 200,
left: 80,
child: Container(
width: 200,
height: 200,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(128.0),
border: Border.all(color: Colors.blue),
),
),
),
Positioned(
top: 225,
left: 105,
child: Container(
width: 150,
height: 150,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(128.0),
border: Border.all(color: Colors.blue),
),
),
),
],
),
),
);
Use this:
Container(
color: Colors.white,
child: Center(
child: Container(
width: 200,
height: 200,
decoration: BoxDecoration(
gradient: const LinearGradient(
colors: [Colors.white,Colors.white, Colors.red, Colors.red, Colors.white,Colors.white],
transform: GradientRotation(pi / 2),
),
borderRadius: BorderRadius.circular(128.0),
),
child: Center(
child: Container(
width: 198,
height: 198,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(120.0),
),
),
),
),
),
),
It leads to this output:
use stack widget and put 2 circle containers with different size as children in stack widget

Flutter show container on other container

I want to show container on top right of other container but its showing inside of it.
My code
Stack(
children: <Widget>[
Container(
decoration: BoxDecoration(
color: Color(0xffd1e6f5),
borderRadius: BorderRadius.all(Radius.circular(10))
),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: SvgPicture.asset(
"assets/icon/notification.svg",
),
),
),
new Positioned( // draw a red marble
top: 0.0,
right: 0.0,
child: Container( decoration: BoxDecoration(
color: Color(0xff009fe1),
borderRadius: BorderRadius.all(Radius.circular(10))
),
child: Padding(
padding: const EdgeInsets.all(3.0),
child: Text('01'),
),),
)
]
)
I want to show it outside a light container like this
You need an external container to simulate the overlap effect.
Check the behavior of that component and try replicate your desired behavior.
Container(
height: 140.0,
width: 140.0,
color: Colors.amber, // set as transparent.
child: Stack(
children: [
Align(
alignment: Alignment.center,
child: Container(
height: 100.0,
width: 100.0,
decoration: const BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.all(Radius.circular(10))
),
),
),
Align(
alignment: Alignment.topRight,
child: Container(
width: 40.0, height: 40.0,
decoration: const BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.all(Radius.circular(10))
)
),
),
],
),
),
In addition to the answer of Marcos. I would like to tell you about this package badges
Example Usage
Badge(
badgeContent: Text('3'),
child: Icon(Icons.settings),
)
Try below code hope its helpful to you.
Container(
height: 100.0,
width: 100.0,
child: Stack(
children: [
Align(
alignment: Alignment.center,
child: Container(
height: 50.0,
width: 50.0,
decoration: const BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.all(
Radius.circular(10),
),
),
child: Icon(
Icons.notifications,
color: Colors.white,
),
),
),
Positioned(
top: 17,
right: 17,
child: Container(
width: 25.0,
height: 25.0,
alignment: Alignment.center,
decoration: BoxDecoration(
color: Colors.blue[200],
borderRadius: BorderRadius.all(
Radius.circular(40),
),
),
child: Text(
'01',
),
),
),
],
),
),
Your result screen ->
You can also use Badge package here
Badge(
badgeColor: Colors.blue,
animationType: BadgeAnimationType.slide,
toAnimate: true,
position: BadgePosition.topEnd(
top: -10,
end: -10,
),
badgeContent: Text(
'01',
),
child: Container(
height: 50.0,
width: 50.0,
decoration: const BoxDecoration(
color: Color(0xffd1e6f5),
borderRadius: BorderRadius.all(
Radius.circular(10),
),
),
child: Icon(
Icons.notifications,
color: Colors.white,
),
),
),
Your result screen using package ->

Placing button at the bottom of container in flutter

How can I create button like below,
Try below code hope its helpful to you. used Stack widget here for that
Stack(
alignment: Alignment.bottomCenter,
children: <Widget>[
Padding(
padding: EdgeInsets.only(top: circleRadius / 2.0),
child: Container(
height: 200,
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
color: Colors.white,
margin: EdgeInsets.all(
16,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisSize: MainAxisSize.min,
children: [
Container(
width: 2,
height: 2,
decoration: ShapeDecoration(
shape: CircleBorder(),
color: Colors.transparent,
),
),
],
),
),
),
),
Container(
width: 100,
height: 40,
decoration: ShapeDecoration(
shape: RoundedRectangleBorder(),
color: Colors.transparent,
),
child: Padding(
padding: EdgeInsets.all(1),
child: DecoratedBox(
child: Center(
child: Text(
'Profile',
style:TextStyle(color: Colors.white,),
textAlign: TextAlign.center,
),
),
decoration: ShapeDecoration(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
color: Colors.blue,
),
),
),
)
],
),
Your Result screen->
Container(
padding: EdgeInsets.all(20),
decoration: BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.all(Radius.circular(20))),
child: TextButton(
child: Text(
"Profile",
style: TextStyle(color: Colors.white),
),
onPressed: () {},
),
),
you can use following code sample...change height according to your need...or use mediaquery for better result:
Container(
height: 275,
child: Stack(
children: [
Container(//container with background color
height: 250,
child: //other widgets
),
Positioned(
bottom: 0,
child: //button here
),
],
),
),

How to make an Icon overlay over an image

I'm new to flutter and not that experienced when it comes to programming in general. So I'm trying to do something like this
But I just can't seem to do it, I tried align properties, padding to make it move left and right, I also tried stacks but I don't have any idea how to do it.
This is my code for the image
Widget buildImage() {
return Padding(
padding: EdgeInsets.only(right: 10, left: 10, top: 20),
child: Align(
alignment: Alignment.bottomLeft,
child: Container(
height: 100,
width: 130,
decoration: BoxDecoration(
image: new DecorationImage(
image: new AssetImage(
"assets/images/profile-image.jpeg",
),
fit: BoxFit.cover,
),
shape: BoxShape.circle,
border: Border.all(
color: Colors.white,
width: 5.0,
),
),
),
));
}
This is my current progress
I would appreciate any help.
Here is the working code
Stack(
alignment: Alignment.bottomRight,
children: <Widget>[
Container(
height: 200,
width: 200,
child: InkWell(
onTap: () => {},
child: ClipRRect(
borderRadius: BorderRadius.circular(100),
child: Container(
height: 200,
width: 200,
color: Colors.grey[200],
child: Icon(Icons.person),
),
),
),
),
Container(
height: 60,
width: 60,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.white,
),
padding: EdgeInsets.all(5),
child: Container(
decoration: BoxDecoration(shape: BoxShape.circle, color: Colors.grey[200]),
child: IconButton(
icon: Icon(Icons.edit),
onPressed: () {},
),
),
),
],
);
This can be achieved with the Stack widget check the docs it has a video explaining it really well.
It lets you positions its children relative to the edges of its box.
You can use Stack to place widget over widget. Here is the working example
Stack(
alignment: Alignment.bottomRight,
children: <Widget>[
Container(
decoration: BoxDecoration(
image: new DecorationImage(
image: new AssetImage(
"assets/images/profile-image.jpeg",
),
fit: BoxFit.cover,
),
shape: BoxShape.circle,
border: Border.all(
color: Colors.white,
width: 5.0,
)),
height: 100,
width: 130,
),
Container(
height: 50,
width: 50,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.white,
),
padding: EdgeInsets.all(5),
child: Container(
decoration:
BoxDecoration(shape: BoxShape.circle, color: Colors.blue),
child: Center(
child: IconButton(
icon: Icon(Icons.edit),
onPressed: () {},
),
),
),
),
],
)

How to add text in a section of a container in flutter?

The result I want to have
My current result
I was trying to add a title section for my categories but the result was not what I expected.
I'm looking to add a title section below each illustration in my categories.
child: Container(
height: 400.0,
width: 500.0,
padding: const EdgeInsets.all(10.0),
decoration: BoxDecoration(
color: ColorPallete.secondColor[50],
borderRadius: BorderRadius.circular(20.0),
),
child: SvgPicture.asset(
'assets/images/svg/megacategory/art__grocery.svg',
),
)
You can use a Column widget to align its contents vertically, in your example you can use it as follow (I have used some online images and colors you can edit it as per your requirement)-
Column(
children: [
SizedBox(height: 50.0),
Container(
height: 100.0,
width: 100.0,
padding: const EdgeInsets.all(10.0),
decoration: BoxDecoration(
color: Colors.orange[50],
borderRadius: BorderRadius.circular(20.0),
),
child: Image.network(
'https://img.icons8.com/cotton/online-shop-2--v2.png',
),
),
SizedBox(height: 10.0),
Text("Title Here")
],
),
It will arrange the contents as follows -
You can read more about Column widget here
child: Container(
height: 400.0,
width: 500.0,
padding: const EdgeInsets.all(10.0),
decoration: BoxDecoration(
color: ColorPallete.secondColor[50],
borderRadius: BorderRadius.circular(20.0),
),
child: Column(
children: [
SvgPicture.asset(
'assets/images/svg/megacategory/art__grocery.svg',
),
Text('Abarrotes')
)
You can wrap it with Column widget so you can add a Text widget under your container.
child: Column(
children: [
Container(
height: 400.0,
width: 500.0,
padding: const EdgeInsets.all(10.0),
decoration: BoxDecoration(
color: ColorPallete.secondColor[50],
borderRadius: BorderRadius.circular(20.0),
),
child: SvgPicture.asset(
'assets/images/svg/megacategory/art__grocery.svg',
),
),
Text("Your text",style: TextStyle(color: Colors.black) ),
],
),
You try put image in decoration instead of child and add text in child container as below.
Container(
decoration: BoxDecoration(
image: DecorationImage(image: NetworkImage(*imageUrl*)),
borderRadius: BorderRadius.all(Radius.circular(6.0)),
),
child: Text(*title*))
As I saw from the answers above you are facing an overflow problem when you are implementing these lines of code:
child: Container(
height: 400.0,
width: 500.0,
padding: const EdgeInsets.all(10.0),
decoration: BoxDecoration(
color: ColorPallete.secondColor[50],
borderRadius: BorderRadius.circular(20.0),
),
child: Column(
children: [
SvgPicture.asset(
'assets/images/svg/megacategory/art__grocery.svg',
),
Text('Abarrotes')
)
So add these two variables under your Widget build:
Widget build(BuildContext context) {
double width,height;
width = MediaQuery.of(context).size.width;//This means that width== the width of the device running the app in double
height = MediaQuery.of(context).size.height;//Same thing with the height
So now that you have the values of the device width and height you can experiment with their proportions:
child: Container(
height: height*x,//for example if you want it to take place in 1/4 of the screen x=0.25
width: width*x,//same thing here
padding: const EdgeInsets.all(10.0),
decoration: BoxDecoration(
color: ColorPallete.secondColor[50],
borderRadius: BorderRadius.circular(20.0),
),
child: Column(
children: [
SvgPicture.asset(
'assets/images/svg/megacategory/art__grocery.svg',
),
Text('Abarrotes')
)