flutter container rounded edges

Master Flutter: Rounded ContainerEdges Magic

By Robert White
AD

In the realm of UI design with Flutter, one of the most commonly utilized widgets is the Container. Its versatility lies in its ability to hold, position, and style its child widget. However, it's the Container's capacity to add style elements like corners that makes it truly stand out, enabling developers to craft compelling user interfaces with ease.

Flutter offers a simple and effective way to add rounded edges to your Containers, enhancing the aesthetic appeal of your app. Let's delve into the process of achieving this effect and explore some examples to bolster your understanding.

Applying Rounded Corners to Flutter Containers

Flutter's Container class provides properties like decoration, which in turn offers a borderRadius property that can be leveraged to add rounded corners. The borderRadius property accepts a Radius object which you can configure to set the border radius for your Container.

AD
several containers with lids are shown in different colors
several containers with lids are shown in different colors
three round containers with dividers on the top and bottom, each containing compartments in different colors
three round containers with dividers on the top and bottom, each containing compartments in different colors
How to Add Border Radius to Container Flutter?
How to Add Border Radius to Container Flutter?

Radius in Flutter can be defined using the Radius class or by combining two Radius objects using the Radius.circular or Radius.elliptical methods. The former generates a circular border while the latter creates an elliptical one.

Using Radius.circular

The Radius.circular method helps create a circular border around your Container. When provided with a number, it returns a circle with that radius at its center. For example:

Home Accessories
Home Accessories
𝗘𝗰𝗼-𝗔𝗻𝗮𝘁𝗵𝗼𝗺𝗲𝘆 THOME’s containers are designed to be reused by replacing the inner containers. The outer containers can flexibly accommodate different capacities of future lines. #thome#thomeprogram Container Packaging Design, Minimalist Plastic Container, Eco-friendly Container Design, Fulfill Container, Minimalist Transparent Container, Recyclable Aluminum Packaging, Thome Cosmetics, Eco-friendly Container Option, Thermo-resistant Containers
𝗘𝗰𝗼-𝗔𝗻𝗮𝘁𝗵𝗼𝗺𝗲𝘆 THOME’s containers are designed to be reused by replacing the inner containers. The outer containers can flexibly accommodate different capacities of future lines. #thome#thomeprogram Container Packaging Design, Minimalist Plastic Container, Eco-friendly Container Design, Fulfill Container, Minimalist Transparent Container, Recyclable Aluminum Packaging, Thome Cosmetics, Eco-friendly Container Option, Thermo-resistant Containers
HAY Tin container, round, red - soft pink
HAY Tin container, round, red - soft pink

Container( decoration: BoxDecoration( borderRadius: BorderRadius.circular(10), ), )

In this example, a container is created with a border radius of 10. The corners of the container are now rounded, with the radius set at 10.

AD

Using Radius.elliptical

The Radius.elliptical method, on the other hand, allows you to define an elliptical border around your Container. It takes two parameters: horizontal and vertical radii. Here's how to use it:

Green Lidded Container - Tall
Green Lidded Container - Tall
three pastel containers sitting on top of a rock
three pastel containers sitting on top of a rock
Floral Column Storage Jar Silicone Mold - Medium
Floral Column Storage Jar Silicone Mold - Medium
three red plastic containers sitting next to each other
three red plastic containers sitting next to each other
Refillable 10ml Cosmetic Container: 3D Printed Creme Jar - Etsy
Refillable 10ml Cosmetic Container: 3D Printed Creme Jar - Etsy
3d Printed Travel Container - Mini Travel Jar - Small Container - Storage Box
3d Printed Travel Container - Mini Travel Jar - Small Container - Storage Box

Container( decoration: BoxDecoration( borderRadius: BorderRadius.only( topLeft: Radius.elliptical(10, 20), bottomRight: Radius.elliptical(30, 40), ), ), )

In this example, the top left corner of the container has a vertical radius of 20 and a horizontal radius of 10, while the bottom right corner has a vertical radius of 40 and a horizontal radius of 30, thus creating an elliptical border around the corners.

AD

Changing Corner Radius Dynamically

Flutter UI allows for animated changes to container properties, including the corner radius. This is particularly useful in scenarios where you want to react to user interaction or animate transitions between states. Let's explore this using an example:

Package Vectors - Download Free High-Quality Vectors | Magnific (formerly Freepik)
Package Vectors - Download Free High-Quality Vectors | Magnific (formerly Freepik)
Starter Set - Petal
Starter Set - Petal
an overhead view of a white and black object
an overhead view of a white and black object
22 container plants that grow beautifully on Florida patios
22 container plants that grow beautifully on Florida patios
a pink and blue container sitting next to each other on a white surface with a gray lid
a pink and blue container sitting next to each other on a white surface with a gray lid
aesthetic picture of edge booster !
aesthetic picture of edge booster !
Pavilion Gift Company - Friends Are Family - 18 oz Mug - Drinkware
Pavilion Gift Company - Friends Are Family - 18 oz Mug - Drinkware
Flat Pack Storage Containers (Mid-assembly)
Flat Pack Storage Containers (Mid-assembly)
Glass food container with silicone-vented glass lid
Glass food container with silicone-vented glass lid
Flat Rack Container - Cubner
Flat Rack Container - Cubner
Honed Square Container - Mushroom / Gold
Honed Square Container - Mushroom / Gold

AnimatedBuilder( animation: yourAnimatedObject, builder: (context, child) => Container( decoration: BoxDecoration( borderRadius: BorderRadius.circular(10 - yourAnimatedObject.value), ), child: Text('Your Text Here'), ), )

In this example, AnimatedBuilder ensures that as yourAnimatedObject changes, the borderRadius of your container animates between states, providing a smooth user experience.

AD

Rounded corners can significantly enhance the user interface of your Flutter app, making it more appealing and engaging. By mastering the usage of Container's corner radius properties, you'll be equipped to craft compelling user interfaces that can captivate and engage your users.

AD