瀏覽代碼

1、新增日程弹框

bakamaka.guan 2 年之前
父節點
當前提交
06a1f3b590
共有 1 個文件被更改,包括 30 次插入6 次删除
  1. 30 6
      lib/popup_layer/popup_layer.dart

+ 30 - 6
lib/popup_layer/popup_layer.dart

@@ -16,12 +16,15 @@ class PopupLayer extends StatefulWidget {
 class _PopupLayerState extends State<PopupLayer> {
   PopupLayerController popupLayerController = Get.find<PopupLayerController>();
   bool _isShowMoreSchedulePopup = false;
+  bool _isNeedCloseMoreSchedulePopup = false;
   bool _isShowSchedulePopup = false;
+  bool _isNeedCloseSchedulePopup = false;
   GlobalKey moreSchedulePopupKey = GlobalKey();
   @override
   void initState() {
     super.initState();
     popupLayerController.onPopupMoreSchedule.addListener(_onPopupMoreSchedule);
+    popupLayerController.onGlobalClick.addListener(_onGlobalClick);
     popupLayerController.onPopupSchedule.addListener(_onPopupSchedule);
   }
 
@@ -30,6 +33,7 @@ class _PopupLayerState extends State<PopupLayer> {
     super.dispose();
     popupLayerController.onPopupMoreSchedule
         .removeListener(_onPopupMoreSchedule);
+    popupLayerController.onGlobalClick.removeListener(_onGlobalClick);
     popupLayerController.onPopupSchedule.removeListener(_onPopupSchedule);
   }
 
@@ -49,26 +53,46 @@ class _PopupLayerState extends State<PopupLayer> {
     });
   }
 
+  /// 收到全局点击事件
+  /// 全局按下时设置 _needClosePopup 为 true
+  /// 弹层组件收到 onPointerUp 时设置 _needClosePopup 为 false
+  /// 全局抬起时判断 _needClosePopup 是否为 true,为 true 则关闭弹层
+  void _onGlobalClick(e, PointerEvent event) {
+    if (event is PointerDownEvent) {
+      _isNeedCloseMoreSchedulePopup = true;
+      _isNeedCloseSchedulePopup = true;
+    } else if (event is PointerUpEvent) {
+      if (_isNeedCloseMoreSchedulePopup) {
+        setState(() {
+          _isShowMoreSchedulePopup = false;
+        });
+      }
+      if (_isNeedCloseSchedulePopup) {
+        setState(() {
+          _isShowSchedulePopup = false;
+        });
+      }
+    }
+  }
+
   @override
   Widget build(BuildContext context) {
     return Stack(
       children: [
         if (_isShowMoreSchedulePopup)
           Listener(
-            behavior: HitTestBehavior.translucent,
+            behavior: HitTestBehavior.deferToChild,
             onPointerUp: (event) {
-              setState(() {
-                _isShowMoreSchedulePopup = false;
-              });
+              _isShowMoreSchedulePopup = false;
             },
             child: _buildMoreSchedulePopup(moreSchedulePopupKey),
           ),
         if (_isShowSchedulePopup)
           Listener(
-            behavior: HitTestBehavior.translucent,
+            behavior: HitTestBehavior.deferToChild,
             onPointerUp: (event) {
               setState(() {
-                _isShowSchedulePopup = false;
+                _isNeedCloseSchedulePopup = false;
               });
               popupLayerController.onCloseSchedulePopup.emit(this, false);
             },