my_calendar.dart 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import 'package:calendar_view/calendar_controller/controller.dart';
  2. import 'package:calendar_view/utils/calendar_util.dart';
  3. import 'package:calendar_view/calendar_page/my_calendar/my_schedule_item.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:get/get.dart';
  6. /// 我的日历模块,是个ListView,可以展开收起
  7. class MyCalendar extends StatefulWidget {
  8. const MyCalendar({super.key});
  9. @override
  10. State<MyCalendar> createState() => _MyCalendarState();
  11. }
  12. class _MyCalendarState extends State<MyCalendar> {
  13. bool _isExpanded = true;
  14. bool _isTitleHover = false;
  15. List<ScheduleType> _scheduleTypeList = [];
  16. CalendarController calendarController = Get.find<CalendarController>();
  17. @override
  18. void initState() {
  19. super.initState();
  20. _scheduleTypeList = calendarController.scheduleTypeList;
  21. calendarController.onDaysListChange.addListener(_onDaysListChange);
  22. }
  23. @override
  24. void dispose() {
  25. super.dispose();
  26. calendarController.onDaysListChange.removeListener(_onDaysListChange);
  27. }
  28. void _onDaysListChange(_, e) {
  29. setState(() {
  30. _scheduleTypeList = calendarController.scheduleTypeList;
  31. });
  32. }
  33. @override
  34. Widget build(BuildContext context) {
  35. return ListView(
  36. shrinkWrap: true,
  37. children: <Widget>[
  38. _buildMyCalendarTitle(),
  39. if (_isExpanded) ..._scheduleTypeList.map(_buildMyCalendarItem),
  40. ],
  41. );
  42. }
  43. Widget _buildMyCalendarTitle() {
  44. return MouseRegion(
  45. cursor: SystemMouseCursors.click,
  46. onEnter: _handleMouseEnter,
  47. onExit: _handleMouseExit,
  48. child: GestureDetector(
  49. onTap: () {
  50. setState(() {
  51. _isExpanded = !_isExpanded;
  52. });
  53. },
  54. child: Container(
  55. height: 40,
  56. decoration: BoxDecoration(
  57. color: _isTitleHover
  58. ? const Color.fromARGB(255, 233, 235, 236)
  59. : Colors.transparent,
  60. borderRadius: BorderRadius.circular(5),
  61. ),
  62. padding: const EdgeInsets.symmetric(horizontal: 10),
  63. // color: const Color.fromARGB(90, 59, 255, 59),
  64. child: Row(
  65. children: [
  66. const Center(
  67. /// TODO[Gavin]: i18n
  68. child: Text(
  69. '我的日历',
  70. style: TextStyle(
  71. color: Color.fromARGB(255, 116, 118, 119),
  72. ),
  73. ),
  74. ),
  75. Expanded(child: Container()),
  76. const Center(
  77. child: Icon(
  78. Icons.more_horiz,
  79. size: 20,
  80. color: Color.fromARGB(255, 116, 118, 119),
  81. ),
  82. ),
  83. const SizedBox(width: 10),
  84. Center(
  85. child: Icon(
  86. _isExpanded ? Icons.expand_less : Icons.expand_more,
  87. size: 20,
  88. color: const Color.fromARGB(255, 116, 118, 119),
  89. ),
  90. ),
  91. ],
  92. ),
  93. ),
  94. ),
  95. );
  96. }
  97. Widget _buildMyCalendarItem(ScheduleType type) {
  98. return MyScheduleItem(
  99. type: type,
  100. onClick: () => calendarController.updateScheduleTypeList(),
  101. );
  102. }
  103. void _handleMouseEnter(PointerEvent details) {
  104. setState(() {
  105. _isTitleHover = true;
  106. });
  107. }
  108. void _handleMouseExit(PointerEvent details) {
  109. setState(() {
  110. _isTitleHover = false;
  111. });
  112. }
  113. }