fix : enabled in buttons

This commit is contained in:
2025-08-04 08:51:06 +03:30
parent e262b0394a
commit 7a3061d9a4
2 changed files with 13 additions and 7 deletions

View File

@@ -18,6 +18,7 @@ class RElevated extends StatelessWidget {
this.isFullWidth = false,
this.isLoading = false,
this.child,
this.enabled = true,
}) : assert(text != null || child != null, 'Either text or child must be provided');
final String? text;
@@ -33,10 +34,11 @@ class RElevated extends StatelessWidget {
final double radius;
final TextStyle? textStyle;
final bool isLoading;
final bool enabled;
@override
Widget build(BuildContext context) {
final bool isEnabled = onPressed != null && !isLoading;
final bool isEnabled = enabled && !isLoading;
return ElevatedButton(
onPressed: isEnabled ? onPressed : null,

View File

@@ -16,7 +16,8 @@ class ROutlinedElevated extends StatefulWidget {
this.child,
this.width,
this.height,
}):assert(text!=null || child != null, 'Either text or child must be provided');
this.enabled = true,
}) : assert(text != null || child != null, 'Either text or child must be provided');
final String? text;
final VoidCallback? onPressed;
@@ -30,6 +31,7 @@ class ROutlinedElevated extends StatefulWidget {
double? radius;
TextStyle? textStyle;
Widget? child;
bool enabled;
@override
State<ROutlinedElevated> createState() => _ROutlinedElevatedState();
@@ -73,14 +75,14 @@ class _ROutlinedElevatedState extends State<ROutlinedElevated> {
child: OutlinedButton(
key: _widgetKey,
statesController: _statesController,
onPressed: widget.onPressed,
onPressed: widget.enabled ? widget.onPressed : null,
style: ButtonStyle(
side: WidgetStateProperty.resolveWith<BorderSide?>((states) {
if (states.contains(WidgetState.pressed)) {
return BorderSide(color: widget.borderColor ?? AppColor.blueNormal, width: 2);
} else if (states.contains(WidgetState.disabled)) {
return BorderSide(
color: widget.borderColor ?? AppColor.blueNormal.withAlpha(38),
color: widget.borderColor?.disabledColor ?? AppColor.blueNormal.withAlpha(38),
width: 2,
);
}
@@ -103,7 +105,9 @@ class _ROutlinedElevatedState extends State<ROutlinedElevated> {
if (states.contains(WidgetState.pressed)) {
return Colors.white;
} else if (states.contains(WidgetState.disabled)) {
return AppColor.blueNormal.withAlpha(38);
return widget.foregroundColor?.disabledColor ??
widget.borderColor?.disabledColor ??
AppColor.blueNormal.disabledColor;
}
return widget.foregroundColor ?? widget.borderColor ?? AppColor.blueNormal;
}),
@@ -115,9 +119,9 @@ class _ROutlinedElevatedState extends State<ROutlinedElevated> {
textStyle: WidgetStateProperty.resolveWith<TextStyle?>((states) {
if (states.contains(WidgetState.pressed)) {
return widget.textStyle?.copyWith(color: Colors.white) ??
AppFonts.yekan20.copyWith(color: Colors.white);
AppFonts.yekan18.copyWith(color: Colors.white);
}
return widget.textStyle ?? AppFonts.yekan20.copyWith(color: AppColor.blueNormal);
return widget.textStyle ?? AppFonts.yekan18.copyWith(color: AppColor.blueNormal);
}),
),
child: widget.child ?? Text(widget.text ?? ''),