|
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, |
|
), |
|
), |
|
); |
|
} |
|
} |
Like this