Browse Source

1、更新日程框

bakamaka.guan 2 years ago
parent
commit
63dfd77646

+ 9 - 1
lib/calendar_page/month_calendar/month_calendar_item.dart

@@ -155,7 +155,15 @@ class _MyWidgetState extends State<MonthDayItem> {
               .scheduleListFilter(widget.dayData.scheduleList),
           onTapShowMore: () {
             popupLayerController.handlePopupMoreSchedule(
-                _monthGridKey, widget.dayData);
+              _monthGridKey,
+              widget.dayData,
+            );
+          },
+          onTapShowSchedule: (value) {
+            popupLayerController.handlePopupMoreSchedule(
+              value,
+              widget.dayData,
+            );
           },
         ),
       ),

+ 16 - 8
lib/calendar_page/month_calendar/schedule_list.dart

@@ -1,5 +1,6 @@
 import 'package:calendar_view/popup_layer/popup_layer_controller.dart';
 import 'package:calendar_view/utils/calendar_util.dart';
+import 'package:calendar_view/utils/event_type.dart';
 import 'package:flutter/material.dart';
 import 'package:get/get.dart';
 
@@ -9,6 +10,7 @@ class ScheduleList extends StatefulWidget {
     required this.maxLines,
     required this.scheduleDataList,
     required this.onTapShowMore,
+    required this.onTapShowSchedule,
   }) : super(key: key);
 
   /// 可容纳的最大日程行数
@@ -23,6 +25,9 @@ class ScheduleList extends StatefulWidget {
   /// 点击显示更多
   final VoidCallback onTapShowMore;
 
+  /// 点击显示日程卡片
+  final ValueCallback onTapShowSchedule;
+
   @override
   ScheduleListState createState() => ScheduleListState();
 }
@@ -31,7 +36,6 @@ class ScheduleListState extends State<ScheduleList> {
   /// 容纳的数量
   int _itemCount = 0;
   PopupLayerController popupLayerController = Get.find<PopupLayerController>();
-
   @override
   void initState() {
     super.initState();
@@ -76,22 +80,26 @@ class ScheduleListState extends State<ScheduleList> {
             widget.scheduleDataList.length - _itemCount + 1);
       }
     }
+    GlobalKey _scheduleListKey = GlobalKey();
+
     ScheduleType scheduleType = widget.scheduleDataList[scheduleIndex].type;
     Schedule schedule = widget.scheduleDataList[scheduleIndex];
     return Material(
       color: Colors.transparent,
       child: InkWell(
+        key: _scheduleListKey,
         customBorder: RoundedRectangleBorder(
           borderRadius: BorderRadius.circular(5),
         ),
         onTap: () {
-          ScaffoldMessenger.of(context).showSnackBar(
-            SnackBar(
-              backgroundColor: scheduleType.color,
-              duration: const Duration(milliseconds: 500),
-              content: Text('点击了${scheduleType.typeName}'),
-            ),
-          );
+          // ScaffoldMessenger.of(context).showSnackBar(
+          //   SnackBar(
+          //     backgroundColor: scheduleType.color,
+          //     duration: const Duration(milliseconds: 500),
+          //     content: Text('点击了${scheduleType.typeName}'),
+          //   ),
+          // );
+          widget.onTapShowSchedule.call(_scheduleListKey);
         },
         hoverColor: const Color.fromARGB(255, 227, 228, 228),
         child: Container(

+ 9 - 0
lib/popup_layer/popup_layer.dart

@@ -20,6 +20,7 @@ class _PopupLayerState extends State<PopupLayer> {
   void initState() {
     super.initState();
     popupLayerController.onPopupMoreSchedule.addListener(_onPopupMoreSchedule);
+    popupLayerController.onPopupSchedule.addListener(_onPopupSchedule);
   }
 
   @override
@@ -27,6 +28,7 @@ class _PopupLayerState extends State<PopupLayer> {
     super.dispose();
     popupLayerController.onPopupMoreSchedule
         .removeListener(_onPopupMoreSchedule);
+    popupLayerController.onPopupSchedule.removeListener(_onPopupSchedule);
   }
 
   /// 收到显示更多日程的事件
@@ -37,6 +39,13 @@ class _PopupLayerState extends State<PopupLayer> {
     });
   }
 
+  /// 收到显示日程的事件
+  void _onPopupSchedule(e, GlobalKey key) {
+    setState(() {
+      moreSchedulePopupKey = key;
+    });
+  }
+
   @override
   Widget build(BuildContext context) {
     return _isShowPopup

+ 9 - 0
lib/popup_layer/popup_layer_controller.dart

@@ -9,6 +9,9 @@ class PopupLayerController extends GetxController {
   /// 弹出层【显示更多日程】事件通知
   FEventHandler<GlobalKey> onPopupMoreSchedule = FEventHandler<GlobalKey>();
 
+  /// 弹出层【显示日程详情】事件通知
+  FEventHandler<GlobalKey> onPopupSchedule = FEventHandler<GlobalKey>();
+
   /// Popup 弹出层相关的数据
   /// 当前需要显示更多的日程数据
   MonthViewDayStructure currMoreScheduleData = MonthViewDayStructure(
@@ -22,6 +25,12 @@ class PopupLayerController extends GetxController {
     onPopupMoreSchedule.emit(this, key);
   }
 
+  void handlePopupSchedule(
+      GlobalKey key, MonthViewDayStructure moreScheduleData) {
+    currMoreScheduleData = moreScheduleData;
+    onPopupSchedule.emit(this, key);
+  }
+
   @override
   void onInit() {
     super.onInit();

+ 3 - 0
lib/utils/event_type.dart

@@ -1,5 +1,8 @@
 typedef FEventCallback<T> = void Function(Object sender, T e);
 
+/// 带数据回调
+typedef ValueCallback<T> = void Function(T value);
+
 class FEventHandler<T> {
   List<FEventCallback<T>>? _callbacks;
   bool _isDispoed = false;