Stack(
children: [
Container(
height: MediaQuery.of(context).size.height * 0.5,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(100.0),
bottomRight: Radius.circular(100.0)),
color: darkBlue,
),
),
Positioned(
bottom: 0,
left: MediaQuery.of(context).size.width / 3,
child: CircleAvatar(
backgroundColor: white,
radius: 70,
child: Image.asset('assets/images/homepage.png'))),
],
)
When I set the value as bottom : 0 in the code, since the image is inside the Stack, it sees it as a border and moves the image to the bottom of the Stack. But what I want is to place the image in the center of the Container, as shown by the black circle in the image.
You need to pass negative half of height to bottom value to get that, don't forget to set Stack's clipBehavior to none. Try this:
Stack(
clipBehavior: Clip.none,// <-- add this
children: [
Container(
height: MediaQuery.of(context).size.height * 0.5,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(100.0),
bottomRight: Radius.circular(100.0)),
color: darkBlue,
),
),
Positioned(
bottom: -100/2,// <-- add this
left: MediaQuery.of(context).size.width / 3,
child: CircleAvatar(
backgroundColor: white,
radius: 70,
child: Image.asset('assets/images/homepage.png'))),
],
),
try this:
Stack(
alignment: Alignment.center
children: [
Container(
height: MediaQuery.of(context).size.height * 0.5,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(100.0),
bottomRight: Radius.circular(100.0)),
color: darkBlue,
),
),
CircleAvatar(
backgroundColor: white,
radius: 70,
child: Image.asset('assets/images/homepage.png'))
],
)
Placing bottom on half image will be bottom:-halfImageHeight, And the default clipBehavior of Stack is hardEdge which is needed to to set Clip.none
Stack(
clipBehavior: Clip.none,
children: [
/// background widgets
Position(
bottom: -70 // while radius is 70
left: MediaQuery.of(context).size.width / 2 - 70, // remove half width , maybe left:0 and right:0 will work as well
Placing center you can use Align widget
Align(
alignment: Alignment.center, //default
child: CircleAvatar(
)
I'm using a container and need to add border rounding on multiple sides. I've tried using borderRadius but I'm getting an error because I'm using the border. Tell me by what method can I add rounding for the container not from all sides, but only from some?
return Container(
width: size.width,
height: size.height,
decoration: BoxDecoration(
border: index == 0
? const Border(
bottom:
BorderSide(width: 2, color: constants.Colors.purpleMain),
)
: const Border(
bottom:
BorderSide(width: 2, color: constants.Colors.purpleMain),
),
),
alignment: Alignment.center,
You can use param borderRadius in BoxDecoration. Parameters of BorderRadius.only are topLeft, topRight, bottomLeft, bottomRight.
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topRight: Radius.circular(4.0), // only top right
),
),
...
)
This question already has answers here:
Add border to a Container with borderRadius in Flutter
(7 answers)
Closed 11 months ago.
I want to add a bottom border to a container that has border radius along the top only. I can see that I cannot add borderRadius and border together in BoxDecoration property. How could I achieve the below look and feel using containers?
So far I can only achieve either rounded corners or have a bottom border, but not both. I want rounded corners across the top and a border across the bottom. Thank you very much!
Container(
padding: const EdgeInsets.all(20),
decoration: const BoxDecoration(
color: Color(0xFFE9F6EB),
// boxShadow: [BoxShadow(color: Colors.green, spreadRadius: 3)],
borderRadius: BorderRadius.only(
topLeft: Radius.circular(6), topRight: Radius.circular(6)),
// border:
// Border(bottom: BorderSide(width: 3.0, color: Colors.green)),
),
child: Row(children: [
const Icon(Icons.check_circle,
color: Color(0xFF69A258), size: 40),
const SizedBox(width: 15),
Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
Text("Valid",
style: TextStyle(color: Colors.green, fontSize: 18)),
Text("Document successfully validated.")
])
]),
),
By adding a boxshadow instead of a border with a spreadRadius of 0. Basically BoxShadow property followed the same concepts as css so this generator helped alot https://cssgenerator.org/box-shadow-css-generator.html
boxShadow: [
BoxShadow(
color: Colors.green, spreadRadius: 0, offset: Offset(0, 3))
],
I am trying to add a border radius to a LinearProgressIndicator in Flutter.
When I replace the LinearProgressIndicator with another widget (e.g. Text) in the code below, it works, as expected.
Container(
decoration: new BoxDecoration(
borderRadius:
new BorderRadius.all(const Radius.circular(20.0))),
child: LinearProgressIndicator(
value: _time,
),
)
1) Using Widget
Container(
margin: EdgeInsets.symmetric(vertical: 20),
width: 300,
height: 20,
child: ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(10)),
child: LinearProgressIndicator(
value: 0.7,
valueColor: AlwaysStoppedAnimation<Color>(Color(0xff00ff00)),
backgroundColor: Color(0xffD6D6D6),
),
),
)
2) Using dependency
List of different types indicator https://pub.dev/packages/percent_indicator
Try this template code
child: Padding(
padding: EdgeInsets.all(15.0),
child: LinearPercentIndicator(
width: MediaQuery.of(context).size.width - 50,
animation: true,
lineHeight: 20.0,
animationDuration: 2000,
percent: 0.9,
linearStrokeCap: LinearStrokeCap.roundAll,
progressColor: Colors.greenAccent,
),
)
Edit: I just wanted to point out my answer doesn't account for rounding the end of the 'value' fill inside the bar, which the OP wanted. However it seems many people came to this question looking for the answer I provided, (as did I before I found the answer and came back to respond).
So if you need the inside of this indicator also to have a rounded edge, as of now I think the accepted answer from Amit is the best route. If the inside of the indicator can have a flat edge and you don't want to use a third party package, I think my answer below is still the best option.
Original:
You actually don't need to use a third party package, and can wrap your LinearProgressIndicator with the ClipRRect widget and give it a circular border radius. If you want to give it a specific thickness/height then you could use a container as an intermediary:
ClipRRect(
borderRadius: BorderRadius.circular(8),
child: Container(
height: 10,
child: LinearProgressIndicator(
value: 0.35, // percent filled
valueColor: AlwaysStoppedAnimation<Color>(Colors.orange),
backgroundColor: Color(0xFFFFDAB8),
),
),
)
would produce this, if placed in another widget with a defined width:
Let's try my custom progress bar, simple and don't use any library :)
class ProgressBar extends StatelessWidget {
final double max;
final double current;
final Color color;
const ProgressBar(
{Key? key,
required this.max,
required this.current,
this.color = AppColors.secondaryColor})
: super(key: key);
#override
Widget build(BuildContext context) {
return LayoutBuilder(
builder: (_, boxConstraints) {
var x = boxConstraints.maxWidth;
var percent = (current / max) * x;
return Stack(
children: [
Container(
width: x,
height: 7,
decoration: BoxDecoration(
color: Color(0xffd3d3d3),
borderRadius: BorderRadius.circular(35),
),
),
AnimatedContainer(
duration: Duration(milliseconds: 500),
width: percent,
height: 7,
decoration: BoxDecoration(
color: color,
borderRadius: BorderRadius.circular(35),
),
),
],
);
},
);
}
}
You can try this code:
Container(
decoration: const BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(40.0))),
child: const ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(20)),
child: LinearProgressIndicator(
minHeight: 5.0,
value: 0.2,
color: Colors.white,
backgroundColor: Color(0xFF3B2D73),
),
),
I am going to leave my answer in case someone is looking for something custom, basic with custom BorderRadius
Container(
height: 24.0,
margin: EdgeInsets.only(top: 12.0, bottom: 2.0),
decoration: BoxDecoration(
color: Colors.grey,
borderRadius: BorderRadius.all(Radius.circular(4.0)),
),
clipBehavior: Clip.antiAlias,
child: FractionallySizedBox(
alignment: Alignment.centerLeft,
widthFactor: 0.57,
heightFactor: 1.0,
child: Container(
decoration: BoxDecoration(
color: Colors.blueAccent,
borderRadius: BorderRadius.all(Radius.circular(4.0)),
),
clipBehavior: Clip.antiAlias,
),
),
),
Feel free to try it out :)
Do not need to wrap LinearPercentIndicator inside a Container widget. You could get the desired output only using LinearPercentIndicator.
See the template code
LinearPercentIndicator(
lineHeight: 40.0,
barRadius: const Radius.circular(20.0),
percent: 0.7,
animation: true,
animationDuration: 1000,
backgroundColor: Color(0xFFD6D6D6),
progressColor: Color(0xFF5BFB82),
),
To make the inner bar rounded, we need to use the following logic :
Make the Outer progress bar rounded, use ClipRRect and set borderRadius
To make the inner bar rounded, we can use Container, where we will make one side (right side) rounded using borderRadius. Then, we will place it on top of our progress bar, using Stack.
The width of the container will be actually the progress shown in the progress bar.
Container(
width: (MediaQuery.of(context).size.width - 30) *
calculateProgressBarValue(Data1, Data2),
height: 6,
decoration: BoxDecoration(
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(CommonDimens.MARGIN_10),
bottomLeft: Radius.circular(CommonDimens.MARGIN_10),
),
color: progressBarColor,
),
Full code :
ClipRRect(
borderRadius: const BorderRadius.all(Radius.circular(10)),
child: Stack(
children: [
ClipRRect(
borderRadius: const BorderRadius.all(Radius.circular(10)),
child: LinearProgressIndicator(
minHeight: 6.0,
valueColor:
AlwaysStoppedAnimation<Color>(Colors.grey),
value: 1,
),
),
Positioned(
right: 0,
child: Container(
width: ((MediaQuery.of(context).size.width) - 30) *
calculateProgressBarValue(Data1,Data2),
height: 6,
decoration: BoxDecoration(
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(CommonDimens.MARGIN_10),
bottomLeft: Radius.circular(CommonDimens.MARGIN_10),
),
color: progressBarColor,
),
),
],
),
);
You can make use of
curved_progress_bar , It has both CurvedCircularProgressIndicator as well as CurvedLinearProgressIndicator, and it works just like normal CircularProgressIndicator and LinearProgressIndicator.
You could try my library (capped_progress_indicator) that does what you want and works exactly like Flutter's original LinearProgressIndicator and CircularProgressIndicator. It not only rounds the ends of the track/background but also the ends of the progress/indicator.
So its just a matter of installing the package and changing your code from
LinearProgressIndicator(
// ...
)
to
import 'package:capped_progress_indicator/capped_progress_indicator.dart';
LinearCappedProgressIndicator(
// ...
)
You can also change the corner radius to your liking
LinearCappedProgressIndicator(), // Circle end (default).
LinearCappedProgressIndicator(cornerRadius: 5), // Rounded end.
LinearCappedProgressIndicator(cornerRadius: 0), // Square end.
As you can see in the Image there is a Container-widget (grey Box) and in it there's a Markdown-widget from the flutter_markdown Package.
I want that the Markdown-element is centered vertially in the Container ( where the yellow marker is) instead of where the Markdown is now ("Internet").
EDIT:
If the only possible solution is to add a fixed width I need to calculate it somehow, because it can be only one or many lines or a long text without line breaks. If there aren't any line breaks the flutter_markdown widget automatically wraps the text into the widget.
How should it look like
child: Container(
constraints: BoxConstraints.expand(
width: MediaQuery.of(context).size.width * 0.9,
height: MediaQuery.of(context).size.width * 0.7,
),
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(10.0)),
color: _color
),
padding: EdgeInsets.all(8.0),
alignment: Alignment.center,
child: Container(
decoration: BoxDecoration(
borderRadius: new BorderRadius.only(
topLeft: new Radius.circular(20.0),
bottomLeft: new Radius.circular(20.0),
),
boxShadow: [
new BoxShadow(
color: _color,
offset: new Offset(5.0, 5.0),
blurRadius: 20.0,
)
],
),
child: Scrollbar(
child: Markdown(
imageDirectory: Store.storageDirectory,
data: _markdownText)),
),
),
Thanks in advance.
Markdown based on ListView and provide the same properties. Works for me:
Center(child: Markdown(
physics: BouncingScrollPhysics(),
shrinkWrap: true,
data: store.subtitle))