/*
 * @Author: XianKaiQun
 * @Date: 2020-06-24 01:53:56
 * @LastEditors  : WuWei
 * @LastEditTime : 2023-05-10 10:09:52
 * @Description: 
 */
import 'package:flutter/material.dart';

import 'wisdom.dart';

class WisTip extends StatelessWidget {
  WisTip({
    Key? key,
    this.plain = false,
    Color color = Colors.red,
    this.shape = BoxShape.rectangle,
    this.left,
    this.right,
    this.top,
    this.bottom,
    Widget? tip,
    required this.content,
  })   : this._tipW = tip == null
            ? null
            : Wisdom(
                color: plain == true ? Colors.white : color,
                padding: EdgeInsets.symmetric(horizontal: 3, vertical: 0),
                shape: shape,
                border:
                    Border.fromBorderSide(BorderSide(color: color, width: 1.1)),
                borderRadius: shape == BoxShape.rectangle
                    ? BorderRadius.circular(1000)
                    : null,
                child: DefaultTextStyle(
                  style: TextStyle(
                    color: plain == true ? color : Colors.white,
                    fontSize: 10,
                    height: 1.1,
                  ),
                  child: tip,
                ),
              ),
        super(key: key);

  ///是否镂空
  final bool? plain;

  ///形状
  ///[BoxShape.circle]强制圆形
  ///[BoxShape.rectangle] 圆角
  final BoxShape? shape;

  ///定位
  final double? left;

  ///定位
  final double? right;

  ///定位
  final double? top;

  ///定位
  final double? bottom;

  ///被包裹Widget
  final Widget? content;

  final Widget? _tipW;

  WisTip.dot({
    double size = 10.0,
    Color color = Colors.red,
    this.left,
    this.right,
    this.top,
    this.bottom,
    required this.content,
  })   : assert(left == null || right == null, '不能同时设置left&&right'),
        assert(top == null || bottom == null, '不能同时设置top&&bottom'),
        this.plain = false,
        this.shape = null,
        this._tipW = Wisdom(
          alignment: Alignment.bottomCenter,
          width: size,
          height: size,
          borderRadius: BorderRadius.circular(size / 2),
          color: color,
        );

  @override
  Widget build(BuildContext context) {
    return Stack(
      clipBehavior: Clip.none,
      children: <Widget>[
        if (content != null) content!,
        if (_tipW != null)
          Positioned(
            left: left,
            right: right,
            top: top,
            bottom: bottom,
            child: _tipW!,
          ),
      ],
    );
  }
}
