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))
),
)
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"),
);
This should be the easiest one ever.
I am coming back to flutter after years away as I am forced to update my old app. Everything has changed!
I am trying to make an ElevatedButton that is square. The default has slightly rounded edges that looks weird when I am making a button the width of the screen.
All I want to know is how I can make this button a square. That's it! No tricks!
ElevatedButton has:
ElevatedButton.styleFrom(
shape: ???,
),
But I can't find any information anywhere online what my options are for shape. Only a few examples on how to make it round or beveled or literally every other shape you can think of except for a simple rectangle :D
Try below code:
ElevatedButton, ButtonStyle, BorderRadius
ElevatedButton(
style: ElevatedButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
//borderRadius: BorderRadius.zero, //Rectangular border
),
),
onPressed: () {},
child: const Text(
'Submit',
),
),
Result->
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'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
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.