Create a rounded button / button with border-radius in Flutter

Cover Image for Create a rounded button / button with border-radius in Flutter
Matheus Mello
Matheus Mello
published a few days ago. updated a few hours ago

๐Ÿ†’๐Ÿ“ Flutter Blog: How to Create a Rounded Button with Border-Radius ๐Ÿ“ฑ๐Ÿ’ช

Are you developing an Android app in Flutter and wondering how to add a cool rounded button? Look no further! In this blog post, we'll explore how to create a rounded button with border-radius in Flutter, address common issues, and provide easy solutions to help you get that sleek design you're looking for. Let's dive in! ๐Ÿš€๐Ÿ”˜

The Challenge: Adding a Rounded Button in Flutter

Our fellow Flutter enthusiast is facing a common UI challenge - creating a rounded button that adds a touch of elegance to their Android app. Luckily, Flutter provides several ways to tackle this problem. Let's begin with a simple solution! ๐ŸŽ‰

Solution 1: Using the RaisedButton Widget (Deprecated Approach)

In earlier versions of Flutter, one common approach was to use the RaisedButton widget and set the shape property to a StadiumBorder. This would create a rounded button in your app. However, please note that the RaisedButton widget has been deprecated since Flutter 2.0 and you should use the ElevatedButton widget instead.

Here's an example of how you can achieve a rounded button using the deprecated RaisedButton:

RaisedButton(
  shape: StadiumBorder(),
  onPressed: () {
    // Button action goes here
  },
  child: Text('Click me!'),
)

โš ๏ธ Remember: Although this approach still works, it's always recommended to use the latest and recommended widgets for better compatibility and future-proofing your app. So, let's move on to the newer and recommended solution! ๐Ÿ˜‰

Solution 2: Using the ElevatedButton Widget (Recommended Approach)

Flutter 2.0 introduced the ElevatedButton widget, which offers a modern way to create buttons with a border-radius. It's a recommended approach as it provides better customization options and aligns with the Flutter team's latest design guidelines.

Here's how you can create a rounded button using the ElevatedButton:

ElevatedButton(
  style: ElevatedButton.styleFrom(
    shape: RoundedRectangleBorder(
      borderRadius: BorderRadius.circular(16),
    ),
  ),
  onPressed: () {
    // Button action goes here
  },
  child: Text('Click me!'),
)

The style property allows us to set various visual properties of the ElevatedButton. In our case, we use the RoundedRectangleBorder with a borderRadius property of 16, which creates a rounded button with a border-radius of 16 pixels.

๐Ÿ“ฃ Calling All Flutter Enthusiasts!

Now that you know how to create a rounded button in Flutter, it's time to put your skills to the test! Experiment with different border-radius values, colors, and button sizes to match your app's unique style. Don't be afraid to get creative! ๐Ÿ’กโœจ

Share your experience and some screenshots of your awesome rounded buttons in the comments below. We'd love to see what you come up with! Let's inspire and empower each other in the Flutter community! ๐Ÿค๐ŸŽจ

Happy coding, Flutter fam! ๐Ÿš€๐Ÿ”ท

P.S. Don't forget to follow our blog for more Flutter tips, tricks, and tutorials. Stay tuned for our next post on how to implement custom button animations! ๐Ÿ˜‰


Remember to add icons, gifs, or screenshots to make the blog post more visually appealing and engaging. Use a conversational tone throughout the post to make it friendly and easy to read.

โœ๏ธ So get your buttons ๐ŸŽ›๏ธ๐Ÿ”˜ ready and start Fluttering away! Happy coding! ๐Ÿš€๐Ÿ’™


More Stories

Cover Image for How can I echo a newline in a batch file?

How can I echo a newline in a batch file?

updated a few hours ago
batch-filenewlinewindows

๐Ÿ”ฅ ๐Ÿ’ป ๐Ÿ†’ Title: "Getting a Fresh Start: How to Echo a Newline in a Batch File" Introduction: Hey there, tech enthusiasts! Have you ever found yourself in a sticky situation with your batch file output? We've got your back! In this exciting blog post, we

Matheus Mello
Matheus Mello
Cover Image for How do I run Redis on Windows?

How do I run Redis on Windows?

updated a few hours ago
rediswindows

# Running Redis on Windows: Easy Solutions for Redis Enthusiasts! ๐Ÿš€ Redis is a powerful and popular in-memory data structure store that offers blazing-fast performance and versatility. However, if you're a Windows user, you might have stumbled upon the c

Matheus Mello
Matheus Mello
Cover Image for Best way to strip punctuation from a string

Best way to strip punctuation from a string

updated a few hours ago
punctuationpythonstring

# The Art of Stripping Punctuation: Simplifying Your Strings ๐Ÿ’ฅโœ‚๏ธ Are you tired of dealing with pesky punctuation marks that cause chaos in your strings? Have no fear, for we have a solution that will strip those buggers away and leave your texts clean an

Matheus Mello
Matheus Mello
Cover Image for Purge or recreate a Ruby on Rails database

Purge or recreate a Ruby on Rails database

updated a few hours ago
rakeruby-on-railsruby-on-rails-3

# Purge or Recreate a Ruby on Rails Database: A Simple Guide ๐Ÿš€ So, you have a Ruby on Rails database that's full of data, and you're now considering deleting everything and starting from scratch. Should you purge the database or recreate it? ๐Ÿค” Well, my

Matheus Mello
Matheus Mello