How can I make such a style for a container - flutter

I want to make the container look like this style container but my container looks like this my container. How can I do this?
Code :
child: Container(
decoration: BoxDecoration(
shape: BoxShape.rectangle,
color: Color(0xffCEFC4C),
borderRadius: BorderRadius.only(topRight: Radius.circular(20))),
width: 327,
height: 56,
alignment: Alignment.center,
child: Text(
'SAVE BUTTON',
style: TextStyle(
color: Colors.black,
fontSize: 16.0,
fontWeight: FontWeight.w500,
),
),
),

you can use something like this
Material(
clipBehavior: Clip.antiAlias,
shape: BeveledRectangleBorder(
borderRadius: BorderRadius.only(
topRight: Radius.circular(20.0),
),
),
child: Container(
height: 100,
decoration: BoxDecoration(
color: Color(0xffCEFC4C),
),
),
),

Related

Custom border for a flutter widget

I have a custom border to draw around a widget. I have attached an image
Can anyone have an idea how to do this in flutter without a custom painter?
Please notice it doesn't have a bottom border.
Container(
height: 100,
width: 200,
alignment: Alignment.center,
decoration: const BoxDecoration(
border: Border(
top: BorderSide(width: 5.0, color: Colors.black),
left: BorderSide(width: 5.0, color: Colors.black),
right: BorderSide(width: 5.0, color: Colors.black),
bottom: BorderSide(width: 0, color: Colors.white),
),
color: Colors.white,
),
child: const Text('OK', textAlign: TextAlign.center, style: TextStyle(color: Color(0xFF000000))),
)
Wrap the widget with Container
Container(
decoration: BoxDecoration(
border: Border.all(width: 5.0, color: Colors.black),
borderRadius: BorderRadius.circular(20.0) )// change value as per your needs
child: //your widget
)
Try below code hope its help to you.
If you want only Top corner are rounded :
Container(
width: double.infinity,
height: 100,
decoration: BoxDecoration(
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(10),
topRight: Radius.circular(10),
),
border: Border.all(
width: 3,
color: Colors.black,
),
),
),
Result top rounded corner:
If you want all container rounded :
Container(
width: double.infinity,
height: 100,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
border: Border.all(
width: 5,
color: Colors.black,
),
),
),
All rounded contaner result:
Please Refer Below code:
Padding(
padding: const EdgeInsets.all(15.0),
child: ClipRRect(
borderRadius:
BorderRadius.all(Radius.circular(7)),
child: Container(
height: 100,
width: double.infinity,
decoration: BoxDecoration(
border: Border(
left: BorderSide(
color: Colors.black,
width: 4.0,
),
top: BorderSide(
color: Colors.black,
width: 4.0,
),
right: BorderSide(
color: Colors.black,
width: 4.0,
),
),
),
child: Center(
child: Text('Custom Border'),
),
),
),
)

Flutter Material different border colors with radius not working

I want to add border color on 3 side only and add border radius seems like in container its not possible i tried its showing some error then i try it with Material and its working fine but issue is i am not able to add borderRadius now. Need to know how can i add border radius with different side colors.
Want to achieve this
And stuck on this
You can see on left side no radius is showing
My code
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Material(
shape: Border(
left: BorderSide(
width: 1,
color: Color(0xffE6E6E6),
),
bottom: BorderSide(
width: 1,
color: Color(0xffE6E6E6),
),
top: BorderSide(
width: 1,
color: Color(0xffE6E6E6),
),
),
child: Container(
width: Width * 0.45,
height: Height * 0.07,
decoration: BoxDecoration(
color: Color(0xffFAFAFA),
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(5),
bottomLeft: Radius.circular(5)),
),
child: Center(
child: Text(
'https://facebook.com/',
style:
TextStyle(color: textGreyColor, fontSize: 15),
)),
),
),
Container(
width: Width * 0.45,
height: Height * 0.07,
child: TextFormField(
key: ValueKey('name'),
style: TextStyle(color: textGreyColor),
decoration: new InputDecoration(
enabledBorder: new OutlineInputBorder(
borderRadius: const BorderRadius.only(
topRight: Radius.circular(5),
bottomRight: Radius.circular(5)),
borderSide: const BorderSide(
color: Color(0xffE6E6E6), width: 1),
),
filled: true,
hintStyle: new TextStyle(
color: textGreyColor, fontSize: 15),
hintText: "Facebook Page",
fillColor: Colors.white,
focusedBorder: OutlineInputBorder(
borderSide: const BorderSide(
color: Color(0xffE6E6E6), width: 1),
borderRadius: const BorderRadius.only(
topRight: Radius.circular(5),
bottomRight: Radius.circular(5)),
),
),
),
),
],
),
You can wrap it with ClipRRect. Not the best solution but it will work
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ClipRRect(
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(5),
bottomLeft: Radius.circular(5)),
child: Material(
shape: Border(
left: BorderSide(
width: 1,
color: Color(0xffE6E6E6),
),
bottom: BorderSide(
width: 1,
color: Color(0xffE6E6E6),
),
top: BorderSide(
width: 1,
color: Color(0xffE6E6E6),
),
),
child: Container(
width: Width * 0.45,
height: Height * 0.07,
decoration: BoxDecoration(
color: Color(0xffFAFAFA),
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(5),
bottomLeft: Radius.circular(5)),
),
child: Center(
child: Text(
'https://facebook.com/',
style: TextStyle(
color: textGreyColor, fontSize: 15),
)),
),
),
),
Container(
width: Width * 0.45,
height: Height * 0.07,
child: TextFormField(
key: ValueKey('name'),
style: TextStyle(color: textGreyColor),
decoration: new InputDecoration(
enabledBorder: new OutlineInputBorder(
borderRadius: const BorderRadius.only(
topRight: Radius.circular(5),
bottomRight: Radius.circular(5)),
borderSide: const BorderSide(
color: Color(0xffE6E6E6), width: 1),
),
filled: true,
hintStyle: new TextStyle(
color: textGreyColor, fontSize: 15),
hintText: "Facebook Page",
fillColor: Colors.white,
focusedBorder: OutlineInputBorder(
borderSide: const BorderSide(
color: Color(0xffE6E6E6), width: 1),
borderRadius: const BorderRadius.only(
topRight: Radius.circular(5),
bottomRight: Radius.circular(5)),
),
),
),
),
],
),
Flutter expect that when you will use the border radius all border will be uniform. So using a custom style for 2 or 3 border and setting a border radius after that does not work.
You can use a outer container which will have the border and radius of four side. After that you place a ClipRRect to cut any background color if that goes over the outer container border. Here's a example output
#override
Widget build(BuildContext context) {
final double borderRadius = 6;
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Padding(
padding: EdgeInsets.all(16),
child: Center(
child: Container(
height: 60,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(borderRadius)),
border: Border.all(color: Colors.grey, width: 1),
),
child: ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(borderRadius)),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
//left child
Expanded(
child: _facebookUrlText(),
),
//middle separator
Container(
width: 1,
color: Colors.grey,
),
//right child
Expanded(
child: _facebookPageInputField(),
),
],
),
),
),
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
),
),
);
}
_facebookUrlText() {
return Container(
height: double.infinity,
color: Color(0xffFAFAFA), //background color of left box
padding: EdgeInsets.symmetric(horizontal: 6),
child: Center(
child: Text(
'https://facebook.com/',
style: TextStyle(color: Colors.grey, fontSize: 15),
),
),
);
}
_facebookPageInputField() {
return TextFormField(
key: ValueKey('name'),
style: TextStyle(color: Colors.grey),
decoration: new InputDecoration(
enabledBorder: new OutlineInputBorder(
borderSide: const BorderSide(color: Colors.transparent, width: 1),
),
filled: true,
hintStyle: new TextStyle(color: Colors.grey, fontSize: 15),
hintText: "Facebook Page",
fillColor: Colors.white,
focusedBorder: OutlineInputBorder(
borderSide: const BorderSide(color: Colors.transparent, width: 1),
),
),
);
}

Reduce the width of only one border of OutlinedButton. Flutter

How can I reduce the width of only one border of OutlinedButton? I need this so that the 2 buttons that are next to each other look like one. Now there is a thick border between the two buttons. I want it to be like this
Code:
ButtonBar(
buttonPadding: EdgeInsets.zero,
children: [
OutlinedButton(
style: OutlinedButton.styleFrom(
side: BorderSide(color: theme.primaryColor),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(5),
bottomLeft: Radius.circular(5))),
),
onPressed: () => {},
child: IconSvg.asset('assets/icons/add.svg'),
),
OutlinedButton(
style: OutlinedButton.styleFrom(
side: BorderSide(color: theme.primaryColor),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(5),
bottomLeft: Radius.circular(5))),
),
onPressed: () => {},
child: IconSvg.asset('assets/icons/add.svg'),
),
],
),
Wrap the button inside a container, you can add border to only specified side.
Container(
decoration: BoxDecoration(
border: Border(
top: BorderSide(
width: 7.0, color: statusColor),
),
left: BorderSide(
width: 7.0, color: statusColor),
),
),
I created a Container and then assigned the 2 OutlinedButton buttons in children of the Row widget inside the Container. Using BoxDecoration, we can set custom widths and colours to each side too.
I didn't have images for + and - so I used a Text widget for both of them.
ButtonBar(
alignment: MainAxisAlignment.start,
buttonPadding: EdgeInsets.zero,
children: [
// container
Container(
decoration: BoxDecoration(
// ---- can also set border widths
border: Border.all(
color: Colors.red,
),
// ---- set border radius
borderRadius: BorderRadius.only(
topLeft: Radius.circular(5.0),
topRight: Radius.circular(5.0),
bottomLeft: Radius.circular(5.0),
bottomRight: Radius.circular(5.0),
),
),
// ---- Row with the 2 buttons
child: Row(
children: [
// ---- 1st Button '+'
OutlinedButton(
style: OutlinedButton.styleFrom(
side: BorderSide(color: Colors.red),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(4),
bottomLeft: Radius.circular(4))),
),
onPressed: () => {},
child: Text('+',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w600,
color: Colors.black,
)),
),
// ---- 2nd Button '-'
OutlinedButton(
style: OutlinedButton.styleFrom(
side: BorderSide(color: Colors.red),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topRight: Radius.circular(4),
bottomRight: Radius.circular(4))),
),
onPressed: () => {},
child: Text('-',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w600,
color: Colors.black,
)),
),
],
),
),
],
)
it works for me
Container(
decoration: BoxDecoration(
border: Border.all(
color: theme.primaryColor
),
borderRadius: BorderRadius.all(
Radius.circular(5),
),
),
child: ButtonBar(
buttonPadding: EdgeInsets.zero,
children: [
Container(
padding: EdgeInsets.symmetric(vertical: 4, horizontal: 8),
decoration: BoxDecoration(
border: Border(
right: BorderSide(
color: theme.primaryColor,
),
),
),
child: IconSvg.asset('assets/icons/widgets/plus.svg'),
),
Container(
padding: EdgeInsets.symmetric(vertical: 4, horizontal: 8),
child: IconSvg.asset('assets/icons/widgets/plus.svg'),
),
],
),
),

Flutter : the two container radius has a small line shadow

Now I am trying to draw a container with the radius border to intersect with another container
But there is a line that remains visible around each container as shown in the picture Does anyone know how to hide it!
there is my code for that
Container(
height: MediaQuery.of(context).size.height * .47,
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
color: Color.fromRGBO(28, 163, 200, 1),
border: null,
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(30.0),
//bottomLeft: Radius.circular(40.0),
),
),
),
Container(
color: Colors.transparent,
child: Container(
width: MediaQuery.of(context).size.width,
color: Color.fromRGBO(28, 163, 200, 1),
child: Container(
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
color: Color.fromRGBO(247, 250, 251, 1),
border: null,
borderRadius: BorderRadius.only(
topRight: Radius.circular(30.0),
//bottomLeft: Radius.circular(40.0),
),
),
child: Padding(
padding: const EdgeInsets.only(left: 20, right: 20, top: 20),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Text(
"القائمة",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 18,
color: Colors.black),
),
Spacer(),
Text(
"عرض الكل",
style: TextStyle(
fontSize: 14,
color: Color.fromRGBO(255, 140, 0, 1)),
),
],
),
),
),
),
),
sounds like a renderer artifact, if you change the top container height ratio it goes away
height: MediaQuery.of(context).size.height * .47, // <-- change this to be 0.5
if you really want that particular height, then use a Stack() rather than embedded Containers
if you change the hight of the container it will render correctly. I have attached a screenshot of the result I get with this:
Column(
children: [
Container(
height: 300, //<--- This is what's causing the issue
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
color: Color.fromRGBO(28, 163, 200, 1),
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(30.0),
//bottomLeft: Radius.circular(40.0),
),
),
),
Container(
// color: Colors.transparent,
child: Container(
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
color: Color.fromRGBO(28, 163, 200, 1),
),
child: Container(
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
color: Color.fromRGBO(247, 250, 251, 1),
borderRadius: BorderRadius.only(
topRight: Radius.circular(30.0),
//bottomLeft: Radius.circular(40.0),
),
),
child: Padding(
padding: const EdgeInsets.only(left: 20, right: 20, top: 20),
child: Row(
children: [
Text(
"القائمة",
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18, color: Colors.black),
),
Spacer(),
Text(
"عرض الكل",
style: TextStyle(fontSize: 14, color: Color.fromRGBO(255, 140, 0, 1)),
),
],
),
),
),
),
),
],
)

Flutter give container rounded border

I'm making a Container(), I gave it a border, but it would be nice to have rounded borders.
This is what I have now:
Container(
width: screenWidth / 7,
decoration: BoxDecoration(
border: Border.all(
color: Colors.red[500],
),
),
child: Padding(
padding: EdgeInsets.all(5.0),
child: Column(
children: <Widget>[
Text(
'6',
style: TextStyle(
color: Colors.red[500],
fontSize: 25),
),
Text(
'sep',
style: TextStyle(
color: Colors.red[500]),
)
],
),
),
);
I tried putting ClipRRect on it, but that crops the border away. Is there a solution for this?
Try using the property borderRadius from BoxDecoration
Something like
Container(
decoration: BoxDecoration(
border: Border.all(
color: Colors.red[500],
),
borderRadius: BorderRadius.all(Radius.circular(20))
),
child: ...
)
To make it completely circle:
Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
),
)
To make it a circle at selected spots:
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topRight: Radius.circular(40.0),
bottomRight: Radius.circular(40.0),
topLeft: Radius.circular(40.0),
bottomLeft: Radius.circular(40.0)),
),
child: Text("hello"),
),
or
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(20)),
),
child: ...
)
You can use like this. If you want border for all the corners you can use like bellow.
Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(
Radius.circular(12.0),
),
),
),
If you want rounded borders for selected sides only you can use like below.
Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(10),
topRight: Radius.circular(10),
),
),
child: Text('Text'),
),
You can use ClipRRect Widget:
ClipRRect (
borderRadius: BorderRadius.circular(5.0),
child: Container(
height: 25,
width: 40,
color: const Color(0xffF8742C),
child: Align(
alignment: Alignment.center,
child: Text("Withdraw"))),
)
Enhancement for the above answer.
Container(
decoration: BoxDecoration(
border: Border.all(
color: Colors.red[500],
),
borderRadius: BorderRadius.circular(20) // use instead of BorderRadius.all(Radius.circular(20))
),
child: ...
)
It can be done in many different ways.
If you have a simple rounded corner to implement use ClipRRect , ClipOval
If you want to have more command over the rounded corneres use BoxDecoration inside the Container
ClipRRect
ClipRRect(
borderRadius: BorderRadius.circular(20),
child: Container(height: 100, width: 100, color: Colors.orange)),
ClipOval
ClipOval(
child: Container(height: 100, width: 100, color: Colors.orange)),
BoxDecoration
Border across all the corners
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.orange),
height: 100,
width: 100,
);
Border in a particular corner
Container(
decoration: const BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(40),
bottomRight: Radius.circular(40)),
color: Colors.orange),
height: 100,
width: 100,
),
Border in a particular axis
Container(
decoration: const BoxDecoration(
borderRadius: BorderRadius.horizontal(
right: Radius.circular(60),
),
color: Colors.orange),
height: 100,
width: 100,
);
To make a complete circle just use shape property :
Container(
padding: const EdgeInsets.all(4),
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.black,
),
child: Icon(
Icons.add,
size: 15.0,
color: Colors.white,
),
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20.0),
border: Border.all(
color: HexColor('#C88A3D'),
width: 3.0
)
),
child: Container(
decoration: new BoxDecoration(borderRadius:
BorderRadius.circular(20.0),
color: Colors.white,),
)
),
The key here is to add a BorderRadius:
Container(
decoration: BoxDecoration(
border: Border.all(
color: Colors.red[340],
),
borderRadius: BorderRadius.all(Radius.circular(35),
),
child: `enter code here`
),
just with put this at the Container
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(30))
),
)
Just simply use circle shape shape: BoxShape.circle in BoxDecoration.
All code be like
Container(
decoration: BoxDecoration(
shape: BoxShape.circle
),
)
Just to show another way to do the same thing.
Might be useful when needs to use InkWell around Container.
Material(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
child: Container(
height: 100,
width: 150,
),
);
SizedBox(
child: (Container(
decoration: BoxDecoration(
color: Colors.grey,
border: Border.all(
color: Colors.grey,
),
borderRadius:
BorderRadius.all(Radius.circular(20))),
child: Column(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Row(
mainAxisAlignment:
MainAxisAlignment.spaceAround,
crossAxisAlignment:
CrossAxisAlignment.center,
children: [
Text('00'),
Padding(
padding: const EdgeInsets.fromLTRB(
2.0, 0, 0, 0),
child: Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.white,
),
child: CustomText(
"2",
color: Colors.black,
),
),
), // text
],
),
],
),
)),
width: 60,
),