my_schedule_item.dart 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import 'package:calendar_view/utils/calendar_util.dart';
  2. import 'package:flutter/material.dart';
  3. class MyScheduleItem extends StatefulWidget {
  4. const MyScheduleItem({super.key, required this.type, required this.onClick});
  5. final ScheduleType type;
  6. final VoidCallback onClick;
  7. @override
  8. State<MyScheduleItem> createState() => _MyScheduleItemState();
  9. }
  10. class _MyScheduleItemState extends State<MyScheduleItem> {
  11. bool _isHover = false;
  12. get _type => widget.type;
  13. @override
  14. Widget build(BuildContext context) {
  15. return MouseRegion(
  16. cursor: SystemMouseCursors.click,
  17. onEnter: _handleMouseEnter,
  18. onExit: _handleMouseExit,
  19. child: GestureDetector(
  20. onTap: () {
  21. setState(() {
  22. _type.isSelected = !_type.isSelected;
  23. });
  24. widget.onClick.call();
  25. },
  26. child: Container(
  27. height: 40,
  28. padding: const EdgeInsets.symmetric(horizontal: 5),
  29. decoration: BoxDecoration(
  30. color:
  31. _isHover ? _type.color.withOpacity(0.08) : Colors.transparent,
  32. borderRadius: BorderRadius.circular(5),
  33. ),
  34. child: Row(
  35. children: [
  36. Center(
  37. child: Checkbox(
  38. splashRadius: 0,
  39. side: BorderSide(color: _type.color, width: 1), // 勾勾的颜色
  40. activeColor: _type.color, // 勾勾的背景色
  41. shape: const CircleBorder(),
  42. value: _type.isSelected,
  43. onChanged: (v) {
  44. setState(
  45. () {
  46. _type.isSelected = v!;
  47. },
  48. );
  49. widget.onClick.call();
  50. },
  51. ),
  52. ),
  53. const SizedBox(width: 5),
  54. Center(
  55. child: Text(_type.typeName),
  56. ),
  57. Expanded(
  58. child: Container(),
  59. ),
  60. if (_isHover)
  61. const Icon(
  62. Icons.more_horiz,
  63. size: 20,
  64. color: Colors.black26,
  65. ),
  66. const SizedBox(width: 10),
  67. ],
  68. ),
  69. ),
  70. ),
  71. );
  72. }
  73. void _handleMouseEnter(PointerEvent details) {
  74. setState(() {
  75. _isHover = true;
  76. });
  77. }
  78. void _handleMouseExit(PointerEvent details) {
  79. setState(() {
  80. _isHover = false;
  81. });
  82. }
  83. }