LCOV - code coverage report
Current view: top level - lib/exercises/widget - pressable_button.dart Coverage Total Hit
Test: lcov.info Lines: 0.0 % 36 0
Test Date: 2025-05-10 20:26:13 Functions: - 0 0

            Line data    Source code
       1              : import 'package:amadeus_proto/constants.dart';
       2              : import 'package:flutter/material.dart';
       3              : 
       4              : class PressableButton extends StatefulWidget {
       5            0 :   const PressableButton(
       6              :       {super.key,
       7              :       required this.body,
       8              :       this.onPressed,
       9              :       required this.height,
      10              :       required this.width,
      11              :       required this.shadowColor,
      12              :       required this.buttonColor,
      13              :       required this.isEnable});
      14              : 
      15              :   final VoidCallback? onPressed;
      16              :   final Widget body;
      17              :   final double height;
      18              :   final double width;
      19              :   final Color shadowColor;
      20              :   final Color? buttonColor;
      21              :   final bool isEnable;
      22              : 
      23            0 :   @override
      24            0 :   State<PressableButton> createState() => _PressableButtonState();
      25              : }
      26              : 
      27              : class _PressableButtonState extends State<PressableButton> {
      28              :   bool _isPressed = false;
      29              : 
      30            0 :   void _onTapDownEvent(_) {
      31            0 :     if (!widget.isEnable) {
      32              :       return;
      33              :     }
      34            0 :     setState(() {
      35            0 :       _isPressed = true;
      36              :     });
      37              :   }
      38              : 
      39            0 :   void _onTapCancelEvent() {
      40            0 :     if (!widget.isEnable) {
      41              :       return;
      42              :     }
      43            0 :     setState(() {
      44            0 :       _isPressed = false;
      45              :     });
      46              :   }
      47              : 
      48            0 :   void _onTapUpEvent(_) {
      49            0 :     if (!widget.isEnable) {
      50              :       return;
      51              :     }
      52            0 :     Future.delayed(const Duration(milliseconds: pressableButtonDuration), () {
      53            0 :       setState(() {
      54            0 :         _isPressed = false;
      55              :       });
      56              :     });
      57            0 :     if (widget.onPressed != null) {
      58            0 :       widget.onPressed!();
      59              :     }
      60              :   }
      61              : 
      62            0 :   @override
      63              :   Widget build(BuildContext context) {
      64            0 :     return GestureDetector(
      65            0 :       onTapDown: _onTapDownEvent,
      66            0 :       onTapUp: _onTapUpEvent,
      67            0 :       onTapCancel: _onTapCancelEvent,
      68            0 :       child: AnimatedContainer(
      69              :         duration: const Duration(milliseconds: fastAnimation),
      70              :         curve: Curves.easeOut,
      71            0 :         width: widget.width,
      72            0 :         height: widget.height,
      73            0 :         decoration: BoxDecoration(
      74            0 :           color: widget.isEnable
      75            0 :               ? (_isPressed
      76            0 :                   ? widget.buttonColor?.withOpacity(0.6) // On press
      77            0 :                   : widget.buttonColor) // Normal
      78            0 :               : Colors.grey.withOpacity(0.8),
      79            0 :           borderRadius: BorderRadius.circular(10),
      80              :         ),
      81            0 :         child: Material(
      82              :           color: Colors.transparent,
      83            0 :           borderRadius: BorderRadius.circular(10),
      84            0 :           child: widget.body,
      85              :         ),
      86              :       ),
      87              :     );
      88              :   }
      89              : }
        

Generated by: LCOV version 2.3-1