Create a rounded button / button with border-radius in Flutter
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Creating aesthetically pleasing user interfaces is a critical component of mobile app development. Flutter, Google's UI toolkit for crafting natively compiled applications for mobile, web, and desktop, offers extensive customization options. Among these, designing buttons with rounded corners using the borderRadius property is essential for creating modern interfaces. This article will explore how to create these rounded buttons in Flutter, enriched with detailed technical explanations and examples.
The Basics of Button Styling in Flutter
Flutter provides several built-in widgets for creating buttons, such as ElevatedButton, OutlinedButton, and TextButton. Each offers different styling options, but they all share a common property called style, which can be used to customize their appearance:
ElevatedButton: A material design button typically used for prominently showing primary actions.OutlinedButton: A button with an outline border that becomes opaque when pressed.TextButton: A button without any border that becomes opaque when pressed.
All these buttons can be styled using the parameter ButtonStyle, which lets you define textStyle, backgroundColor, foregroundColor, overlayColor, shadowColor, elevation, padding, minimumSize, side, shape, and more.
Creating a Rounded Button
To create a rounded button, you need to make use of the shape property within ButtonStyle. The shape attribute utilizes RoundedRectangleBorder allowing you to define the borderRadius.
Here's an example of how to create a rounded button using the ElevatedButton widget in Flutter:
Detailed Explanation
Widgets and Properties
ElevatedButton: A button made prominent through elevation and background color.RoundedRectangleBorder: Used to apply rounded corners to the button.borderRadius: Defines the radius of the corners. In this example,BorderRadius.circular(30.0)is used, indicating that each corner should be 30 pixels in radius.
ButtonStyle Customization
Using the ButtonStyle widget provides more control over button customization. Here's an example:
Enhancing User Interface
Customizing buttons can significantly enhance user interaction. Consider the following tactics:
- Color Schemes: Align button colors with your application's theme.
- Elevation and Shadows: Use elevation to give depth to buttons, making them appear more interactive.
- Padding and Sizing: Ensure appropriate padding and size to enhance usability.
Summary Table
| Parameter | Property/Class | Description |
| Button Type | ElevatedButton, OutlinedButton, TextButton | Widgets to create buttons with different styles |
| Style Property | ButtonStyle | Allows customization of button appearance |
| Shape for Rounded | RoundedRectangleBorder | Class to round the corners of a button |
| BorderRadius | BorderRadius.circular(value) | Sets the corner radius, where value is in pixels |
| Color Customization | backgroundColor
foregroundColor | Defines colors for button and text |
Conclusion
Creating a button with a border-radius in Flutter is straightforward, leveraging the flexible styling capabilities through its ButtonStyle and shape properties. By understanding and utilizing these properties, developers can create highly customized and visually appealing buttons that enhance user experience in their applications. Customize further with colors, sizes, and shadows for even more personalized designs.

