import 'package:fis_ui/index.dart';
import 'package:flyinsono/pages/main/home/widgets/listener.dart';
import 'package:flyinsono/pages/schedule/calendar/popup_layer/popup_layer_controller.dart';
import 'package:flutter/material.dart';

/// 全局事件监听器，用于搭配popup_layer使用
/// 用于监听全局点击事件，当点击到popup_layer以外的区域时，关闭popup_layer
class GlobalClickListener extends FStatelessWidget {
  const GlobalClickListener(
      {Key? key, required this.child, required this.controller})
      : super(key: key);

  final FWidget child;
  final PopupLayerController controller;

  @override
  FWidget build(BuildContext context) {
    return FListener(
      behavior: HitTestBehavior.translucent,
      onPointerDown: (event) {
        controller.onGlobalClick.emit(this, event);
      },
      onPointerUp: (event) {
        controller.onGlobalClick.emit(this, event);
      },
      child: child,
    );
  }
}
