Flutter :- Create circular border around icons - flutter

I want to create circular borders around the icons as shown in the image.
Container(
margin: EdgeInsets.all(20),
padding: EdgeInsets.all(10),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(100),
color: Colors.white,
border: Border.all(
width: 2
)
),
child: Icon(Icons.arrow_downward,color: Colors.white,),
)
I don't need cuts in the circular borders as they are shown in the image but the complete circular border, I have also tried this code =>This Answer

I am doing some mistakes in my above code. but I have figured out and here is the new code.
Container(
margin: EdgeInsets.all(20),
padding: EdgeInsets.all(10),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(100),
border: Border.all(width: 2, color: Colors.white)),
child: Icon(
Icons.cancel,
color: Colors.white,
),
)),
Also if you want to make complete Widget clickable then you can use it like this.
GestureDetector(
onTap: () {
//Navigator.of(context).pop();
},
child: new Align(
alignment: Alignment.bottomRight,
child: Container(
margin: EdgeInsets.all(20),
padding: EdgeInsets.all(10),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(100),
border: Border.all(width: 2, color: Colors.white)),
child: Icon(
Icons.cancel,
color: Colors.white,
),
)),
),

Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(color: Colors.white)
),
child: Icon(Icons.check, color: Colors.white,),
)
or you can use Material if you're going to need some fancy effects:
Material(
color: Colors.transparent,
shape: CircleBorder(
side: BorderSide(color: Colors.white)
),
child: Icon(Icons.check, color: Colors.white,),
)

Updated: OutlinedButton (instead of deprecated OutlineButton)
OutlinedButton(
onPressed: () {},
style: ButtonStyle(
shape: MaterialStateProperty.all<RoundedRectangleBorder>(RoundedRectangleBorder(
borderRadius: BorderRadius.circular(100),
side: BorderSide(color: Colors.green),
)),
),
child: Icon(Icons.print, color: Colors.green),
)
Original response:
I think that the easiest way is to use an OutlineButton:
OutlineButton(
onPressed: () { },
shape: CircleBorder(),
borderSide: BorderSide(color: Colors.green),
child: Icon(Icons.print, color: Colors.green),
)

You can also go with FloatingActionButton.

Related

How can I make such a style for a container

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

Stretch a Border inside Button

I want to make a button with two rounded borders inside each other.
It should look like this
But currently it looks like this
I tried to set a BoxDecoration to a Container and tried to expand the Container with Expanded or SizedBox.expand but it just doesn't stretch
return FittedBox(
child: RaisedButton(
padding: EdgeInsets.all(2),
onPressed: () {},
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
side: BorderSide(color: Colors.red, width: 3)
),
child: Padding(
padding: EdgeInsets.all(3),
child: Expanded(
child: Container(
child: Text("Text"),
decoration: BoxDecoration(
border: Border.all(color: Colors.blue, width: 3),
borderRadius: BorderRadius.circular(10),
),
),
)
)
)
);
Is there a better way to do draw a border inside a button?
Use GestureDetector flutter to get the button work, and use
Container()
Center()
to achieve your aforementioned design. Also, read about BoxDecoration class. It will help you in great extent. Rest you will get to know from the below code itself.
Code
GestureDetector(
onTap: () => print('Hello'),
child: Container(
height: MediaQuery.of(context).size.height * 0.1,
width: MediaQuery.of(context).size.width * 0.2,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(12.0),
// play with width to get the width of the border
border: Border.all(color: Colors.red, width: 5.0),
// play with blurRadius, and offset for the shadow
boxShadow: [BoxShadow(color: Colors.grey, blurRadius: 9.0, offset: Offset(5.0, 5.0))]
),
child: Container(
// play with margin for inside border
margin: EdgeInsets.all(6.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12.0),
// play with width to get the width of the border
border: Border.all(color: Colors.blue, width: 5.0)
),
child: Center(
child: Text('Text', textAlign: TextAlign.center)
)
)
)
)
Result
Remove the FittedBox and wrap the inner Container with a SizedBox.expand:
RaisedButton(
padding: EdgeInsets.all(2),
onPressed: () {},
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
side: BorderSide(color: Colors.red, width: 3)),
child: Padding(
padding: EdgeInsets.all(3),
child: SizedBox.expand(
child: Container(
child: Center(child: Text("Text")),
decoration: BoxDecoration(
border: Border.all(color: Colors.blue, width: 3),
borderRadius: BorderRadius.circular(10),
),
),
)))
Result:

How to add a border color to an OutlineButton

How can I add a border color to an OutlineButton? I tried setting a highlightedBorderColor, but it is not working. How can I solve this issue?
This is my code:
OutlineButton(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
onPressed:(){},child: Padding(
padding: const EdgeInsets.all(12),
child: Text("add to cart",style: TextStyle(color: Colors.red,fontSize: 20),),
),highlightedBorderColor: Colors.red,
),
Add the following line to your code:
borderSide: BorderSide(width: 2.0, color: Colors.red),
This should change the border color of your button to red
Take a try with it:
OutlineButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
borderSide: BorderSide(color: Colors.pink, width: 1),
onPressed: () {},
child: Padding(
padding: const EdgeInsets.all(12),
child: Text(
"add to cart",
style: TextStyle(color: Colors.red, fontSize: 20),
),
),
)

Add border to a Container with borderRadius in Flutter

Container(
child: Text(
'This is a Container',
textScaleFactor: 2,
style: TextStyle(color: Colors.black),
),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.white,
border: Border(
left: BorderSide(
color: Colors.green,
width: 3,
),
),
),
height: 50,
),
This is supposed to show a rounded-edged container with a green left border 3px wide, and the child Text "This is a Container". However, it just shows a rounded-edged container with an invisible child and an invisible left border.
When I take out the borderRadius object, the child Text and the green left border is visible, but introducing it hides the left border and child Text again.
The major problem seems to be the custom left border, because using border: Border.all(width: 0) and borderRadius: BorderRadius.circular(10) makes the edges rounded as needed and also shows the child. But now I cant apply the green left border which is quite important in this particular setup.
So is there something I'm doing wrong, or is this a bug in flutter, or is it just something that is not allowed?
Thank you in advance.
Edit: The image below is the end result. The colors don't matter
It's not possible to add border: and borderRadius: at the same time, you'll get this error:
A borderRadius can only be given for uniform borders.
You can achieve what you want using the borderRadius: and a boxShadow: instead of border: like this:
boxShadow: [
BoxShadow(color: Colors.green, spreadRadius: 3)
]
Your sample code would be like this:
Container(
child: Text(
'This is a Container',
textScaleFactor: 2,
style: TextStyle(color: Colors.black),
),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.white,
boxShadow: [
BoxShadow(color: Colors.green, spreadRadius: 3),
],
),
height: 50,
),
Edit: To achieve the example you now provided, you could do this:
Container(
padding: EdgeInsets.only(left: 12.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10.0),
color: Colors.green,
),
height: 50,
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topRight: Radius.circular(10.0),
bottomRight: Radius.circular(10.0)),
color: Colors.white,
),
child: Text(
'This is a Container',
textScaleFactor: 2,
style: TextStyle(color: Colors.black),
),
),
),
Another solution:
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10.0),
color: Colors.white,
),
height: 50,
child: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Container(
width: 12.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(10.0),
bottomLeft: Radius.circular(10.0)),
color: Colors.green,
),
),
Text(
'This is a Container',
textScaleFactor: 2,
style: TextStyle(color: Colors.black),
)
],
),
),
There is an answer here
Container(
decoration: BoxDecoration(
border: Border.all(
color: Color(0xFFF05A22),
style: BorderStyle.solid,
width: 1.0,
),
color: Colors.transparent,
borderRadius: BorderRadius.circular(30.0),
),
),
This might be so late but also it might be useful for others.
You can wrap your Container inside a ClipRRect, give the ClipRRect the radius and give the Container the border!
Example:
ClipRRect(
borderRadius: const BorderRadius.all(Radius.circular(16.0)),
child: Container(
height: 100,
width: double.maxFinite,
padding: const EdgeInsets.all(16.0),
decoration: BoxDecoration(
border: Border(
left: BorderSide(width: 8.0, color: Colors.green),
),
),
),
),
This should do the UI you lastly posted.
If you want to achieve borderRadius you could also use a PhysicalModel, but you'll have to provide colour. You also can have a shadow for your widget.
PhysicalModel(
color: Colors.red,
elevation: 5,
shadowColor: Colors.blue,
borderRadius: BorderRadius.circular(20),
child: SizedBox(width: 75, height: 75),
)
I think an easier way inspired by #pablo 's answer would be to just make a boxShadow with and offset but without any blur.
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.vertical(
top: Radius.circular(10),
),
boxShadow: [
// to make elevation
BoxShadow(
color: Colors.black45,
offset: Offset(2, 2),
blurRadius: 4,
),
// to make the coloured border
BoxShadow(
color: Colors.blue,
offset: Offset(0, 4),
),
],
),
The decoration above will give us an elevated box which has a blue border in the bottom.
Another benefit of this approcah is that you can use it with
borderRadius: BorderRadius.circular(num)
Which means you can have a container with all rounded sides + a colored border.
Please note that the coloured border comes under the original shadow. This is done to prevent the elevation color from darkening the border.
I archieve do a Inkwell (that simulate a button) circular with an icon inside :
InkWell(
onTap: (){},
child: Container(
width: 50,
height: 50,
decoration: ShapeDecoration(
shape: CircleBorder(), //here we set the circular figure
color: Colors.red
),
child: Center(
child: Icon(
Icons.email,
size: 30,
color: Colors.white,
)
),
)
)
link example of result: https://images.vexels.com/media/users/3/140138/isolated/preview/88e50689fa3280c748d000aaf0bad480-icono-de-ronda-de-correo-electronico-1.png
////Hope this will work for you,Thanks
import 'package:flutter/material.dart';
class System extends StatefulWidget {
const System({Key? key}) : super(key: key);
#override
_SystemState createState() => _SystemState();
}
class _SystemState extends State<System> {
#override
Widget build(BuildContext context) {
return Scaffold(
body:Padding(
padding: const EdgeInsets.only(top:80.0),
child: Column(
children: [
ClipRRect(
borderRadius: const BorderRadius.all(Radius.circular(16.0)),
child: Padding(
padding: const EdgeInsets.all(15.0),
child: ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Container(
height: 100,
width: double.maxFinite,
padding: const EdgeInsets.all(16.0),
decoration: const BoxDecoration(
color: Color(0xffF6EBEC),
border: Border(
bottom: BorderSide(width: 8.0, color: Color(0xffA24949)),
),
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
const CircleAvatar(
backgroundColor: Color(0xffA24949),
child: Icon(Icons.close,
color: Color(0xffF6EBEC), size: 40),
),
const SizedBox(width: 10),
Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
Text("Invalid",
style: TextStyle(color: Color(0xffA24949), fontSize: 18)),
SizedBox(
width: 243,
child: Text("Details do not match the issuer records",overflow: TextOverflow.ellipsis,maxLines: 1,))
])
],
),
),
),
),
),
SizedBox(height: 20,),
ClipRRect(
borderRadius: const BorderRadius.all(Radius.circular(16.0)),
child: Padding(
padding: const EdgeInsets.all(15.0),
child: ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Container(
height: 100,
width: double.maxFinite,
padding: const EdgeInsets.all(16.0),
decoration: const BoxDecoration(
color: Color(0xFFE9F6EB),
border: Border(
bottom: BorderSide(width: 8.0, color: Color(0xFF69A258),),
),
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
const CircleAvatar(
backgroundColor: Color(0xFF69A258),
child: Icon(Icons.check_rounded,
color: Color(0xFFE9F6EB), size: 40),
),
const SizedBox(width: 15),
Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
Text("Valid",
style: TextStyle(color: Color(0xFF69A258), fontSize: 18)),
Text("Document successfully validated.")
])
]),
),
),
),
),
],
),
),
);
}
}

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