I need some help with building a user interface for my app. While browsing Dribbble, I came across a design that I think would be simple and fast to replicate. However, I’m struggling with creating a Container that has a unique borderRadius in Flutter.
I plan to add a black appBar with a leading and actions for the two icons and then create a Container in the body. However, I can’t seem to figure out how to achieve the non-standard borderRadius on the bottom right corner.
Can you please help me with this? Thank you in advance for your assistance.
4
Answers
There are multiple ways to achieve this. One would be with a
CustomClipper
but I think the same effect can be obtained using aStack
and widgets for the corners with a simple border radius.https://dartpad.dev/?id=51c04550077960bdad72c0b3bf5063c9
I have achieved this similar feature while developing ‘message box’ in my chatting application. This is how I created curviness from one side of a container.
There are several approaches to achieve this. Here’s one way to do it:
CustomClipper
is a powerful tool in Flutter for creating shapes. Here in another file, You can define aCustomClipper
class that extendsCustomClipper<Path>
to create a curved shape. Then, apply this CustomClipper to the AppBar to achieve the desired curved effect.AppBar:
CustomClipper file:
Feel free to adjust the parameters of the
CustomClipper
to customize the curves according to your specific design.Implement a custom
BoxBorder
BoxBorder
is used with the FlutterContainer
‘sBoxDecoration
, so writing a custom implementation compliments this API, and lets you neatly control the edge inset dimensions so childWidgets
are aligned properly, and overall a custom BoxBorder is flexible for which designs it supports, since it uses a canvas to draw the shape to the screen, only mathematics is the limit.Usage and result
Here a scroll view is passed as a child to the container using the custom
ChatBubbleBorder
, this shows that the content is rendered within the expecteddimensions
.