import 'package:flutter/material.dart';
import 'package:vnoteapp/components/floating_window/floating_window_model.dart';

/// [FloatingWindowSharedDataWidget]悬浮窗数据共享Widget
class FloatingWindowSharedDataWidget extends InheritedWidget {
  const FloatingWindowSharedDataWidget(
      {super.key, required this.data, required Widget child})
      : super(child: child);

  ///[data]悬浮窗共享数据
  final FloatingWindowModel data;

  /// 静态方法[of]方便直接调用获取共享数据
  static FloatingWindowSharedDataWidget? of(BuildContext context) {
    return context
        .dependOnInheritedWidgetOfExactType<FloatingWindowSharedDataWidget>();
  }

  @override
  bool updateShouldNotify(FloatingWindowSharedDataWidget oldWidget) {
    /// 数据发生变化则发布通知
    return oldWidget.data != data && data.deleteIndex != -1;
  }
}
