import 'package:flutter/material.dart';

class MultipleClickButton extends StatefulWidget {
  final int clickCount;
  final VoidCallback onTriggered;
  final Widget child;

  MultipleClickButton({
    required this.clickCount,
    required this.onTriggered,
    required this.child,
  });

  @override
  _MultipleClickButtonState createState() => _MultipleClickButtonState();
}

class _MultipleClickButtonState extends State<MultipleClickButton> {
  int _currentClickCount = 0;

  void _handleTap() {
    setState(() {
      _currentClickCount++;
    });

    if (_currentClickCount >= widget.clickCount) {
      widget.onTriggered();
      _currentClickCount = 0; // 重置点击计数
    }
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: _handleTap,
      child: widget.child,
    );
  }
}
