button_for_block.dart 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_screenutil/flutter_screenutil.dart';
  3. class ButtonForBlock extends StatefulWidget {
  4. final String title;
  5. final double? width;
  6. final double? height;
  7. final void Function()? onTap;
  8. final double? fontSize;
  9. final Color? bgColor;
  10. final BoxBorder? border;
  11. final double? radius;
  12. const ButtonForBlock({
  13. Key? key,
  14. required this.title,
  15. this.onTap,
  16. this.width,
  17. this.height,
  18. this.fontSize,
  19. this.bgColor=const Color(0xFF00aaFF),
  20. this.border,
  21. this.radius,
  22. }) : super(key: key);
  23. @override
  24. State<ButtonForBlock> createState() => _ButtonForBlockState();
  25. }
  26. class _ButtonForBlockState extends State<ButtonForBlock> {
  27. late bool isOn = false;
  28. @override
  29. Widget build(BuildContext context) {
  30. return GestureDetector(
  31. onTap: widget.onTap,
  32. onTapDown: (e)=>{setState(()=>{isOn=true})},
  33. onTapUp: (e)=>{setState(()=>{isOn=false})},
  34. onTapCancel: ()=>{setState(()=>{isOn=false})},
  35. child: Container(
  36. height: widget.height ?? 35.h,
  37. alignment: Alignment.center,
  38. width: widget.width ?? 280.w,
  39. decoration: BoxDecoration(
  40. color: isOn? const Color(0xff007ab6): widget.bgColor,
  41. borderRadius: BorderRadius.circular(widget.radius ?? (widget.height != null? widget.height!/2: 35.h/2)),
  42. border: widget.border
  43. ),
  44. child: Text(widget.title, style: TextStyle(color: Colors.white, fontSize: widget.fontSize ?? 15.sp)),
  45. ),
  46. );
  47. }
  48. }