Adding just a left side border decoration - flutter

I'm aware of this post how to assign a border to e.g. a Container.
Unfortunately, I failed to find a hint how to only draw the left edge of a Container as a border.
How to assign a border only to one edge of a Widget / Container?

You can add one side border like so
Container(
decoration: BoxDecoration(
border: Border(left: BorderSide(width: 1, color: Colors.red)
),
child: //...,
)
There are also right, top, and bottom params

Related

How can I just make bottomappbar's top border color orange?

I have this BottomAppBar and I want to make it a transparent background while keeping the top border color orange.
Is there any way that I can do this?
------ EDIT
EXAMPLE 1)
EXAMPLE 2)
CODE)
Container(
decoration: BoxDecoration(
border: Border(top: BorderSide(color: Colors.yellow, width: 2))),
child:..... )

Why boxShadow can change the background color of the container?

I'm adding a BoxShadow to a Container so I add property BoxShadow and choose the color. But I found I changed the background color of the container at the same time. I can't find the reason. Though I have gotten that I can avoid this by adding property color in decoration, but I am really puzzle about it. Below is the code segment.
decoration: BoxDecoration(
//when I remove this line, background color will change with the BoxShadow color
color: StatisticColor.white,
boxShadow: [
BoxShadow(
color: StatisticColor.grey.withOpacity(0.2),
spreadRadius: 3,
blurRadius: 3,
offset: Offset(0, 0), // changes position of shadow
),
],
border: Border.all(
color: StatisticColor.grey,
),
borderRadius: BorderRadius.circular(4.0),
),
Adding BoxShadow to a Container without any color property defined will change how the Container looks like. By default, the color of a Container is set to transparent. BoxShadow adds a shadow effect on the edges of the Container. Offsetting it will make the BoxShadow move its x and y-position. That is why you see that the background color of the Container change when adding BoxShadow. Also, I would recommend using Card. It is easier to add shadows to a widget using it and it adds a small BorderRadius to the widget. Here is an example:
Card(
elevation:5, //Optional, this intensifies the shadow applied
child: MyWidget()
)

Why doesn't a draggable container get rounded corners when dragging?

i am developing as a hobby, and is started on a card system where you can pull cards with text, i made my cards in a class of its own, with the following decoration:
decoration: new BoxDecoration(
color: color,
border: Borders.all(),
borderRadius: BorderRadius.circular(MediaQuery.of(context).size.width * 0.02)
)
And it works as it should except when im putting it in my draggable stack, and start dragging the card around, it looks like there is a white container behind it, but only when im dragging it, the code for the draggable is:
Draggable(
child: card,
feedback: Material(child:card),
childWhenDragging: Container(),
onDragEnd: (details) {setState(() {
cards.remove(card);
});}
),
Edit: I solved it by adding the border radius tag to the Material widget, and then giving it the same border rules as the card decoration has

Flutter: ClipRRect vs Container with BoxDecoration

I know that ClipRRect has additional options like custom clipper. But if I need just a simple border radius is there any performance difference? Which one is more recommended?
If your goal is to create a rounded border, you must use clippers only in the last situation, when containers may not help. For example, images can draw over rounded borders, so you have no other option unless clipping the image.
how about shape, shape vs cliprrect
RaisedButton(
onPressed: () {},
child: Text('Test'),
shape: RoundedRectangleBorder(
side: BorderSide.none,
borderRadius: BorderRadius.all(Radius.circular(50))
),
)

Flutter BoxDecoration’s background color overrides the Container's background color, why?

I have a Flutter Container widget and I defined a color for it (pink), but for some reason, the color in BoxDecoration overrides it (green). Why?
new Container(
color: Colors.pink,
decoration: new BoxDecoration(
borderRadius: new BorderRadius.circular(16.0),
color: Colors.green,
),
);
Container’s color is shorthand for BoxDecoration’s color, so BoxDecoration's color in the Container's decoration property overrides its Container's color.
Problem:
You can't use color and decoration at the same time. From docs:
The color and decoration arguments cannot both be supplied, since it would potentially result in the decoration drawing over the background color. To supply a decoration with a color, use decoration: BoxDecoration(color: color).
Solutions:
Use only color:
Container(
color: Colors.red
)
Use only decoration and provide color here:
Container(
decoration: BoxDecoration(color: Colors.red)
)
only set background color use this code
new Container(
color: Colors.pink,
);
if set background color with radius or shape then use color inside decoration
Container(
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(17)),
child:SizeBox());
Flutter team says that color property in BoxDecoration() is quite frequently used in applying background color to Container widget. As such they have put a separate shorthand for color property in Container widget. So, when we use both color property and BoxDecoration() color property in same Container widget, an assertion will be thrown as follows:
Cannot provide both a color and a decoration
The color argument is just a shorthand for "decoration: new BoxDecoration(color: color)".