feat: added content & disabled state
This commit is contained in:
@@ -15,11 +15,12 @@ class AnimatedDialogButton extends StatefulWidget {
|
|||||||
this.buttonConstraints,
|
this.buttonConstraints,
|
||||||
this.buttonType = ButtonType.primary,
|
this.buttonType = ButtonType.primary,
|
||||||
this.isDescructive = false,
|
this.isDescructive = false,
|
||||||
|
this.content,
|
||||||
});
|
});
|
||||||
|
|
||||||
final String buttonText;
|
final String buttonText;
|
||||||
|
|
||||||
final VoidCallback onPressed;
|
final VoidCallback? onPressed;
|
||||||
|
|
||||||
final BoxConstraints? buttonConstraints;
|
final BoxConstraints? buttonConstraints;
|
||||||
|
|
||||||
@@ -27,6 +28,8 @@ class AnimatedDialogButton extends StatefulWidget {
|
|||||||
|
|
||||||
final bool isDescructive;
|
final bool isDescructive;
|
||||||
|
|
||||||
|
final Widget? content;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<AnimatedDialogButton> createState() => _AnimatedDialogButtonState();
|
State<AnimatedDialogButton> createState() => _AnimatedDialogButtonState();
|
||||||
}
|
}
|
||||||
@@ -38,28 +41,40 @@ class _AnimatedDialogButtonState extends State<AnimatedDialogButton> {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final textStyling = _getTextStyling();
|
final textStyling = _getTextStyling();
|
||||||
final buttonDecoration = _getButtonDecoration();
|
final buttonDecoration = _getButtonDecoration();
|
||||||
|
final isDisabled = widget.onPressed == null;
|
||||||
|
|
||||||
return GestureDetector(
|
return IgnorePointer(
|
||||||
onTapDown: (_) => setState(() => _isPressed = true),
|
ignoring: isDisabled,
|
||||||
onTapUp: (_) => setState(() => _isPressed = false),
|
child: Opacity(
|
||||||
onTapCancel: () => setState(() => _isPressed = false),
|
opacity: isDisabled ? 0.4 : 1.0,
|
||||||
onTap: widget.onPressed,
|
child: GestureDetector(
|
||||||
child: AnimatedScale(
|
onTapDown: (_) => setState(() => _isPressed = true),
|
||||||
scale: _isPressed ? 0.95 : 1.0,
|
onTapUp: (_) => setState(() => _isPressed = false),
|
||||||
duration: const Duration(milliseconds: 100),
|
onTapCancel: () => setState(() => _isPressed = false),
|
||||||
child: AnimatedOpacity(
|
onTap: widget.onPressed,
|
||||||
opacity: _isPressed ? 0.6 : 1.0,
|
child: AnimatedScale(
|
||||||
duration: const Duration(milliseconds: 100),
|
scale: _isPressed ? 0.95 : 1.0,
|
||||||
child: Center(
|
duration: const Duration(milliseconds: 100),
|
||||||
child: Container(
|
child: AnimatedOpacity(
|
||||||
constraints: widget.buttonConstraints,
|
opacity: _isPressed ? 0.6 : 1.0,
|
||||||
decoration: buttonDecoration,
|
duration: const Duration(milliseconds: 100),
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
child: Center(
|
||||||
margin: const EdgeInsets.symmetric(vertical: 8),
|
child: Container(
|
||||||
child: Text(
|
constraints: widget.buttonConstraints,
|
||||||
widget.buttonText,
|
decoration: buttonDecoration,
|
||||||
style: textStyling,
|
padding: const EdgeInsets.symmetric(
|
||||||
textAlign: TextAlign.center,
|
horizontal: 16,
|
||||||
|
vertical: 12,
|
||||||
|
),
|
||||||
|
margin: const EdgeInsets.symmetric(vertical: 8),
|
||||||
|
child: widget.buttonText == ''
|
||||||
|
? widget.content!
|
||||||
|
: Text(
|
||||||
|
widget.buttonText,
|
||||||
|
style: textStyling,
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user