04-29-2024, 07:31 AM
I'm working on a Flutter project where I need to create a button that has rounded corners. I am aware that Flutter provides a wide variety of widgets that can be customized extensively, but I'm having a bit of trouble figuring out the best way to create a rounded button. I want the button to be reusable throughout my application, so I'm also looking for a solution that allows for flexibility in terms of the button's dimensions and the degree of the roundness.
For some context, here's what I currently have:
As you can see, I have a basic button that takes in text and an onPressed callback, but I haven't been able to get the rounded corners the way I want them. What is the best practice for achieving this in Flutter? I assume there's a way to do this using the `style` property of the `ElevatedButton`, but I'm not sure about the specifics.
For some context, here's what I currently have:
Code:
class MyButton extends StatelessWidget {
final String text;
final VoidCallback onPressed;
MyButton({
required this.text,
required this.onPressed
});
@override
Widget build(BuildContext context) {
return ElevatedButton(
onPressed: onPressed,
child: Text(text),
// The button's style needs to be defined here to make rounded corners
);
}
}
As you can see, I have a basic button that takes in text and an onPressed callback, but I haven't been able to get the rounded corners the way I want them. What is the best practice for achieving this in Flutter? I assume there's a way to do this using the `style` property of the `ElevatedButton`, but I'm not sure about the specifics.