How ListTile shape parameter works in Flutter?
ListTile(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
side: BorderSide(color: Colors.black),
),
title: Text('data'),
)
This piece of code not reflecting rounded border(not even any border)!
Any ideas how to make this happen and use shape property of ListTile
I have seen certain examples depicting ListTile as child for Card, Container, etc. and then it works
Then what does Shape do and how to use it in ListTile
ListTile shape property is designed to round the InkWell effect. By applying borderRadius, you can only notice the ripple effect (splash color) limitation on your ListTile. The border side: BorderSide(//....) is not taken into account. If you anyway would like to have border on your ListTile, consider wrapping it in another widget, Container for instance, on which you'll use your border.
Related
Can a ContinuousRectangleBorder (AKA Squircle, Superellipse) shape be used as a template for masking another widget?
Context
I'm trying to mask a widget using ClipRRect but the customization options it offers only include traditional border radius which doesn't quite generate the same shape as a container decorated with ContinuousRectangleBorder
Example:
In this approach, the ClipRRect destroys completely the original shape of the ContinuousRectangleBorder if its radius is too big, if it is too small it won't clip both the filter and the container appropiately. I tried with elliptical radiuses but still it does not look as expected
ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(40)),
child: BackdropFilter(
// Filter
filter: ImageFilter.blur(
sigmaX: 20,
sigmaY: 20,
),
// Container with ContinuousRectangleBorder
child: Container(
constraints: BoxConstraints(maxWidth: 600),
decoration: ShapeDecoration(
color: Colors.blue,
shape: ContinuousRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(80)),
),
),
child: Padding(
padding: const EdgeInsets.all(30.0),
child: Text("Hola World"),
),
),
),
);
What I've Tried
I tried using an Stack with two layers:
Stack
|- Layer 1: BackdropFilter inside a traditional ClipRRect hoping to simulate the shape of the ContinuousRectangleBorder behind the real ContinuousRectangleBorder without affecting the real geometry of it.
|- Layer 2: ContinuousRectangleBorder decoration to the final Container.
The problem with this approach is that I could not find a way for the widget within the Layer 1 to occupy the entire width and height of its brother in Layer 2
Hypothesis
Stack: I think this is the closest I've been to solve this case, but it is not the best solution since it simulates the result. (And I'm still stuck where I can't make the Layer 1 container to fill all the space available in the stack.
I read about about the ClipPath widget but it takes a Path as an argument and I have not been able to convert the ShapeDecoration to that type and use it as a mask.
It may be another way to create the ContinuousRectangleBorder look in order to use it as a mask and a container? I found it is also called squircle / superellipse but the packages and solutions to recreate it use a ShapeDecoration just as ContinuousRectangleBorder does.
Maybe an alternative way to make a mask that takes the ContinuousRectangleBorder as an argument and wraps its child?
Open discussion
I'm aware the last 2 hypothesis are a bit far from the original question but I'm open to make things in other ways.
Thank you all for your help.
Thanks to #pskink advice, the correct way to achieve this is by using a ClipPath and passing the ContinuousRectangleBorder as a shape of a ShapeBorderClipper
Example:
ClipPath(
clipper: ShapeBorderClipper(
shape: ContinuousRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(80),
),
),
),
child: Text("Hola World"),
);
I am learning Theme and ThemeData for Flutter.
I can comfortable deal with colors, however I am missing a global BorderRadius setting.
How to make (via ThemeData) that all widgets will have BorderRadius 0 by default (sharp corners)?
Yes, that is possible. You can change the borderRadius for every button type. To do so, add the following lines to your ThemeData:
textButtonTheme: TextButtonThemeData(
style: TextButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
),
You can see that all of your TextButtons should now have a borderRadius of 8. This works for all other buttons accordingly.
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
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))
),
)
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)".