// Author: fengshengxiong
// Date: 2024/6/30
// Description: 全局音乐播放栏

import 'package:flutter/material.dart';
import 'package:get/get.dart';

import 'music_bar_view.dart';

class MusicBar {
  static final MusicBar _instance = MusicBar._();
  factory MusicBar() => _instance;
  MusicBar._();

  OverlayEntry? overlayEntry;
  var isShow = false.obs;

  /// 显示音乐栏
  show() {
    if (Get.isBottomSheetOpen != null && Get.isBottomSheetOpen!) {
      return;
    }
    if (overlayEntry == null && Get.context != null) {
      overlayEntry = OverlayEntry(builder: (BuildContext context) {
        return MusicBarView();
      });
      Overlay.of(Get.context!).insert(overlayEntry!);
      isShow.value = true;
    }
  }

  /// 隐藏音乐栏
  void hide() {
    overlayEntry?.remove();
    overlayEntry = null;
    isShow.value = false;
  }
}
