import 'package:calendar_view/calendar_controller/controller.dart'; import 'package:calendar_view/utils/calendar_util.dart'; import 'package:calendar_view/calendar_page/my_calendar/my_schedule_item.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; /// 我的日历模块,是个ListView,可以展开收起 class MyCalendar extends StatefulWidget { const MyCalendar({super.key}); @override State createState() => _MyCalendarState(); } class _MyCalendarState extends State { bool _isExpanded = true; bool _isTitleHover = false; List _scheduleTypeList = []; CalendarController calendarController = Get.find(); @override void initState() { super.initState(); _scheduleTypeList = calendarController.scheduleTypeList; calendarController.onDaysListChange.addListener(_onDaysListChange); } @override void dispose() { super.dispose(); calendarController.onDaysListChange.removeListener(_onDaysListChange); } void _onDaysListChange(_, e) { setState(() { _scheduleTypeList = calendarController.scheduleTypeList; }); } @override Widget build(BuildContext context) { return ListView( shrinkWrap: true, children: [ _buildMyCalendarTitle(), if (_isExpanded) ..._scheduleTypeList.map(_buildMyCalendarItem), ], ); } Widget _buildMyCalendarTitle() { return MouseRegion( cursor: SystemMouseCursors.click, onEnter: _handleMouseEnter, onExit: _handleMouseExit, child: GestureDetector( onTap: () { setState(() { _isExpanded = !_isExpanded; }); }, child: Container( height: 40, decoration: BoxDecoration( color: _isTitleHover ? const Color.fromARGB(255, 233, 235, 236) : Colors.transparent, borderRadius: BorderRadius.circular(5), ), padding: const EdgeInsets.symmetric(horizontal: 10), // color: const Color.fromARGB(90, 59, 255, 59), child: Row( children: [ const Center( /// TODO[Gavin]: i18n child: Text( '我的日历', style: TextStyle( color: Color.fromARGB(255, 116, 118, 119), ), ), ), Expanded(child: Container()), const Center( child: Icon( Icons.more_horiz, size: 20, color: Color.fromARGB(255, 116, 118, 119), ), ), const SizedBox(width: 10), Center( child: Icon( _isExpanded ? Icons.expand_less : Icons.expand_more, size: 20, color: const Color.fromARGB(255, 116, 118, 119), ), ), ], ), ), ), ); } Widget _buildMyCalendarItem(ScheduleType type) { return MyScheduleItem( type: type, onClick: () => calendarController.updateScheduleTypeList(), ); } void _handleMouseEnter(PointerEvent details) { setState(() { _isTitleHover = true; }); } void _handleMouseExit(PointerEvent details) { setState(() { _isTitleHover = false; }); } }