123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- 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<MyCalendar> createState() => _MyCalendarState();
- }
- class _MyCalendarState extends State<MyCalendar> {
- bool _isExpanded = true;
- bool _isTitleHover = false;
- List<ScheduleType> _scheduleTypeList = [];
- CalendarController calendarController = Get.find<CalendarController>();
- @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: <Widget>[
- _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;
- });
- }
- }
|