79 lines
2.1 KiB
Dart
79 lines
2.1 KiB
Dart
import 'package:auto_size_text/auto_size_text.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:manager_app/constants.dart';
|
|
|
|
class RoundedButton extends StatelessWidget {
|
|
final String text;
|
|
final Function press;
|
|
final IconData? icon;
|
|
final Color color, textColor;
|
|
final double fontSize;
|
|
final double? vertical;
|
|
final double? horizontal;
|
|
|
|
const RoundedButton(
|
|
{Key? key,
|
|
required this.text,
|
|
required this.press,
|
|
this.icon,
|
|
this.color = kPrimaryColor,
|
|
this.textColor = kWhite,
|
|
required this.fontSize,
|
|
this.vertical,
|
|
this.horizontal})
|
|
: super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return TextButton(
|
|
style: ButtonStyle(
|
|
padding: MaterialStateProperty.all(EdgeInsets.symmetric(
|
|
vertical: vertical ?? 12,
|
|
horizontal: horizontal ?? (icon == null ? 20 : 15),
|
|
)),
|
|
backgroundColor: MaterialStateProperty.all(color),
|
|
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
|
|
RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(30.0),
|
|
))),
|
|
onPressed: () => {press()},
|
|
child: getValue(icon));
|
|
}
|
|
|
|
getValue(icon) {
|
|
if (icon != null) {
|
|
return Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
children: [
|
|
Center(
|
|
child: AutoSizeText(
|
|
text,
|
|
style: new TextStyle(
|
|
color: textColor,
|
|
fontSize: fontSize,
|
|
fontWeight: FontWeight.w400),
|
|
maxLines: 2,
|
|
maxFontSize: fontSize,
|
|
textAlign: TextAlign.center,
|
|
),
|
|
),
|
|
SizedBox(width: 10),
|
|
Icon(
|
|
icon,
|
|
color: textColor,
|
|
size: fontSize + 8,
|
|
)
|
|
],
|
|
);
|
|
} else {
|
|
return AutoSizeText(
|
|
text,
|
|
style: new TextStyle(
|
|
color: textColor, fontSize: fontSize, fontWeight: FontWeight.w400),
|
|
maxLines: 2,
|
|
textAlign: TextAlign.center,
|
|
);
|
|
}
|
|
}
|
|
}
|