more_operate_button.dart 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import 'package:flutter/material.dart';
  2. import 'package:fis_theme/theme.dart';
  3. import 'package:flyinsono/lab/color/lab_colors.dart';
  4. class MoreOperateButton extends StatefulWidget {
  5. MoreOperateButton({
  6. super.key,
  7. this.onClick,
  8. this.name = '更多',
  9. this.icon = Icons.more_horiz,
  10. });
  11. final VoidCallback? onClick;
  12. final String name;
  13. final IconData icon;
  14. final ValueNotifier<bool> clicked = ValueNotifier<bool>(false);
  15. @override
  16. State<MoreOperateButton> createState() => _MoreOperateButtonState();
  17. }
  18. class _MoreOperateButtonState extends State<MoreOperateButton> {
  19. bool _isHover = false;
  20. @override
  21. Widget build(BuildContext context) {
  22. Color bgColor = _isHover ? LabColors.base400 : Colors.transparent;
  23. return MouseRegion(
  24. cursor: SystemMouseCursors.click,
  25. onEnter: _handleMouseEnter,
  26. onExit: _handleMouseExit,
  27. child: GestureDetector(
  28. onTap: () {
  29. widget.clicked.value = !widget.clicked.value;
  30. widget.onClick?.call();
  31. },
  32. child: Container(
  33. padding: EdgeInsets.all(5),
  34. decoration: BoxDecoration(
  35. color: bgColor,
  36. borderRadius: BorderRadius.circular(5),
  37. ),
  38. child: Row(
  39. children: [
  40. Icon(
  41. widget.icon,
  42. size: 20,
  43. color: LabColors.base800,
  44. ),
  45. SizedBox(width: 10),
  46. Center(
  47. child: DefaultTextStyle(
  48. style: TextStyle(
  49. decoration: TextDecoration.none,
  50. color: LabColors.text700,
  51. fontFamily: FTheme.ins.localeSetting.fontFamily,
  52. ),
  53. child: Text(
  54. widget.name,
  55. ),
  56. ),
  57. ),
  58. ],
  59. ),
  60. ),
  61. ),
  62. );
  63. }
  64. void _handleMouseEnter(PointerEvent details) {
  65. setState(() {
  66. _isHover = true;
  67. });
  68. }
  69. void _handleMouseExit(PointerEvent details) {
  70. setState(() {
  71. _isHover = false;
  72. });
  73. }
  74. }