Files
rasadyar_application/lib/presentation/widget/buttons/text_button.dart
2025-04-09 17:05:38 +03:30

78 lines
2.4 KiB
Dart

import 'package:flutter/material.dart';
import 'package:rasadyar_app/presentation/common/app_color.dart';
import 'package:rasadyar_app/presentation/common/app_fonts.dart';
class RTextButton extends StatefulWidget {
RTextButton({
super.key,
required this.text,
required this.onPressed,
this.foregroundColor,
this.backgroundColor,
this.borderColor,
this.disabledBackgroundColor,
this.radius,
this.textStyle,
this.width = 150.0,
this.height = 56.0,
});
final String text;
final VoidCallback? onPressed;
final double width;
final double height;
Color? foregroundColor;
Color? backgroundColor;
Color? borderColor;
Color? disabledBackgroundColor;
double? radius;
TextStyle? textStyle;
@override
State<RTextButton> createState() => _RTextButtonState();
}
class _RTextButtonState extends State<RTextButton> {
@override
Widget build(BuildContext context) {
return TextButton(
style: ButtonStyle(
side: WidgetStatePropertyAll(BorderSide.none),
backgroundColor: WidgetStateProperty.resolveWith<Color?>((states) {
if (states.contains(WidgetState.pressed)) {
return widget.backgroundColor ?? AppColor.blueNormal;
} else if (states.contains(WidgetState.hovered)) {
return widget.backgroundColor?.withAlpha(38) ?? AppColor.blueNormal.withAlpha(38);
} else if (states.contains(WidgetState.disabled)) {
return widget.disabledBackgroundColor ?? Colors.transparent;
}
return Colors.transparent;
}),
foregroundColor: WidgetStateProperty.resolveWith<Color?>((states) {
if (states.contains(WidgetState.pressed)) {
return Colors.white;
} else if (states.contains(WidgetState.disabled)) {
return AppColor.blueNormal.withAlpha(38);
}
return AppColor.blueNormal;
}),
shape: WidgetStatePropertyAll(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(widget.radius ?? 8),
),
),
fixedSize: WidgetStatePropertyAll(Size(widget.width, widget.height)),
padding: WidgetStatePropertyAll(EdgeInsets.zero),
textStyle: WidgetStatePropertyAll(
widget.textStyle ??
AppFonts.yekan24.copyWith(color: AppColor.blueNormal),
),
),
onPressed:widget.onPressed,
child: Text(widget.text),
);
}
}