Skip to content

Instantly share code, notes, and snippets.

@minhdangoz
Created April 16, 2024 04:40
Show Gist options
  • Save minhdangoz/acd629c23c07d5f8e42e3d001bcbcf44 to your computer and use it in GitHub Desktop.
Save minhdangoz/acd629c23c07d5f8e42e3d001bcbcf44 to your computer and use it in GitHub Desktop.
Create Flutter rounded button widget
import 'package:flutter/material.dart';
class RoundedButton extends StatelessWidget {
const RoundedButton({
super.key,
required this.text,
required this.press,
this.textColor = Colors.white,
this.gradient,
this.color,
this.icon,
this.width,
this.radius = 59,
this.height = 50,
this.freeHeight = false,
});
final String text;
final Function()? press;
final Color textColor;
final LinearGradient? gradient;
final Color? color;
final IconData? icon;
final double? width;
final double? height;
final bool freeHeight;
final double radius;
@override
Widget build(BuildContext context) {
double? height = this.height;
if (freeHeight) {
height = null;
} else if (height == null) {
height = 50;
}
return Container(
width: width ?? double.infinity,
height: height,
margin: const EdgeInsets.symmetric(vertical: 9),
decoration: BoxDecoration(
gradient: press != null ? gradient : null,
color: press != null ? color : Colors.grey,
borderRadius: BorderRadius.circular(radius),
// boxShadow: [
// BoxShadow(
// color: Color(0xFF9B9B9B).withOpacity(0.25),
// spreadRadius: 4,
// blurRadius: 9,
// offset: Offset(2, 0), // changes position of shadow
// ),
// ],
),
child: ElevatedButton(
onPressed: press,
style: ElevatedButton.styleFrom(
// padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 20),
backgroundColor: Colors.transparent,
shadowColor: Colors.transparent,
elevation: 1,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(radius),
),
),
child: icon != null
? Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Icon(icon),
Text(
text,
style: TextStyle(
color: textColor,
fontSize: 18,
fontWeight: FontWeight.w400),
textAlign: TextAlign.center,
),
],
)
: Text(
text,
style: TextStyle(
color: textColor,
fontSize: 18,
fontWeight: FontWeight.w400),
textAlign: TextAlign.center,
),
),
);
}
}
@minhdangoz
Copy link
Author

Screenshot 2024-04-16 at 11 40 32

Like this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment