fix : enabled in buttons
This commit is contained in:
@@ -18,6 +18,7 @@ class RElevated extends StatelessWidget {
|
|||||||
this.isFullWidth = false,
|
this.isFullWidth = false,
|
||||||
this.isLoading = false,
|
this.isLoading = false,
|
||||||
this.child,
|
this.child,
|
||||||
|
this.enabled = true,
|
||||||
}) : assert(text != null || child != null, 'Either text or child must be provided');
|
}) : assert(text != null || child != null, 'Either text or child must be provided');
|
||||||
|
|
||||||
final String? text;
|
final String? text;
|
||||||
@@ -33,10 +34,11 @@ class RElevated extends StatelessWidget {
|
|||||||
final double radius;
|
final double radius;
|
||||||
final TextStyle? textStyle;
|
final TextStyle? textStyle;
|
||||||
final bool isLoading;
|
final bool isLoading;
|
||||||
|
final bool enabled;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final bool isEnabled = onPressed != null && !isLoading;
|
final bool isEnabled = enabled && !isLoading;
|
||||||
|
|
||||||
return ElevatedButton(
|
return ElevatedButton(
|
||||||
onPressed: isEnabled ? onPressed : null,
|
onPressed: isEnabled ? onPressed : null,
|
||||||
|
|||||||
@@ -16,7 +16,8 @@ class ROutlinedElevated extends StatefulWidget {
|
|||||||
this.child,
|
this.child,
|
||||||
this.width,
|
this.width,
|
||||||
this.height,
|
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 String? text;
|
||||||
final VoidCallback? onPressed;
|
final VoidCallback? onPressed;
|
||||||
@@ -30,6 +31,7 @@ class ROutlinedElevated extends StatefulWidget {
|
|||||||
double? radius;
|
double? radius;
|
||||||
TextStyle? textStyle;
|
TextStyle? textStyle;
|
||||||
Widget? child;
|
Widget? child;
|
||||||
|
bool enabled;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<ROutlinedElevated> createState() => _ROutlinedElevatedState();
|
State<ROutlinedElevated> createState() => _ROutlinedElevatedState();
|
||||||
@@ -73,14 +75,14 @@ class _ROutlinedElevatedState extends State<ROutlinedElevated> {
|
|||||||
child: OutlinedButton(
|
child: OutlinedButton(
|
||||||
key: _widgetKey,
|
key: _widgetKey,
|
||||||
statesController: _statesController,
|
statesController: _statesController,
|
||||||
onPressed: widget.onPressed,
|
onPressed: widget.enabled ? widget.onPressed : null,
|
||||||
style: ButtonStyle(
|
style: ButtonStyle(
|
||||||
side: WidgetStateProperty.resolveWith<BorderSide?>((states) {
|
side: WidgetStateProperty.resolveWith<BorderSide?>((states) {
|
||||||
if (states.contains(WidgetState.pressed)) {
|
if (states.contains(WidgetState.pressed)) {
|
||||||
return BorderSide(color: widget.borderColor ?? AppColor.blueNormal, width: 2);
|
return BorderSide(color: widget.borderColor ?? AppColor.blueNormal, width: 2);
|
||||||
} else if (states.contains(WidgetState.disabled)) {
|
} else if (states.contains(WidgetState.disabled)) {
|
||||||
return BorderSide(
|
return BorderSide(
|
||||||
color: widget.borderColor ?? AppColor.blueNormal.withAlpha(38),
|
color: widget.borderColor?.disabledColor ?? AppColor.blueNormal.withAlpha(38),
|
||||||
width: 2,
|
width: 2,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -103,7 +105,9 @@ class _ROutlinedElevatedState extends State<ROutlinedElevated> {
|
|||||||
if (states.contains(WidgetState.pressed)) {
|
if (states.contains(WidgetState.pressed)) {
|
||||||
return Colors.white;
|
return Colors.white;
|
||||||
} else if (states.contains(WidgetState.disabled)) {
|
} 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;
|
return widget.foregroundColor ?? widget.borderColor ?? AppColor.blueNormal;
|
||||||
}),
|
}),
|
||||||
@@ -115,9 +119,9 @@ class _ROutlinedElevatedState extends State<ROutlinedElevated> {
|
|||||||
textStyle: WidgetStateProperty.resolveWith<TextStyle?>((states) {
|
textStyle: WidgetStateProperty.resolveWith<TextStyle?>((states) {
|
||||||
if (states.contains(WidgetState.pressed)) {
|
if (states.contains(WidgetState.pressed)) {
|
||||||
return widget.textStyle?.copyWith(color: Colors.white) ??
|
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 ?? ''),
|
child: widget.child ?? Text(widget.text ?? ''),
|
||||||
|
|||||||
Reference in New Issue
Block a user