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

@immutable
class DragScaleContainer extends StatefulWidget {
  Widget child;

  /// 双击内容是否一致放大，默认是true，也就是一致放大
  /// 如果为false，第一次双击放大两倍，再次双击恢复原本大小
  bool doubleTapStillScale;
  ValueChanged<ScaleChangedModel> scaleChangedCallback; // 图片缩放倍数改变回调函数
  Function() pointerDownCallback; // 图片指针按下回调函数
  Function() pointerUpCallback; // 图片指针弹起回调函数

  DragScaleContainer({
    Key key,
    @required this.child,
    this.scaleChangedCallback,
    this.pointerDownCallback,
    this.pointerUpCallback,
    this.doubleTapStillScale = true,
  });

  @override
  State<StatefulWidget> createState() {
    return _DragScaleContainerState();
  }
}

class _DragScaleContainerState extends State<DragScaleContainer> {
  @override
  Widget build(BuildContext context) {
    return ClipRect(
      child: TouchableContainer(
        child: widget.child,
        doubleTapStillScale: widget.doubleTapStillScale,
        scaleChangedCallback: widget.scaleChangedCallback,
        pointerDownCallback: widget.pointerDownCallback,
        pointerUpCallback: widget.pointerUpCallback,
      ),
    );
  }
}
