imageButton.dart 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import 'package:flutter/material.dart';
  2. class ImageButton extends StatelessWidget {
  3. final Size buttonSize;
  4. final String image;
  5. final Size imageSize;
  6. final Color bgColor;
  7. final double borderRadius;
  8. final Color borderColor;
  9. final double borderWidth;
  10. final VoidCallback onTap;
  11. ImageButton({
  12. required Size buttonSize,
  13. required this.image,
  14. Size? imageSize,
  15. Color bgColor = Colors.white,
  16. this.borderRadius = 5,
  17. Color? borderColor,
  18. this.borderWidth = 1,
  19. required this.onTap,
  20. })
  21. : buttonSize = buttonSize,
  22. imageSize = imageSize ?? buttonSize,
  23. bgColor = bgColor,
  24. borderColor = borderColor ?? bgColor
  25. ;
  26. @override
  27. Widget build(BuildContext context) {
  28. return GestureDetector(
  29. onTap: onTap,
  30. child: Container(
  31. width: buttonSize.width,
  32. height: buttonSize.height,
  33. decoration: BoxDecoration(
  34. color: bgColor,
  35. shape: BoxShape.rectangle,
  36. borderRadius: BorderRadius.all(Radius.circular(borderRadius)),
  37. border: Border.all(color: borderColor),
  38. ),
  39. child: Center(
  40. child: Image.asset(
  41. image,
  42. width: imageSize.width,
  43. height: imageSize.height,
  44. ),
  45. ),
  46. ),
  47. );
  48. }
  49. }