import 'package:flutter/material.dart';
import 'package:twong/utils/image_utils.dart';
import 'package:twong/utils/index.dart';

class CircleCheckBox extends StatefulWidget {
  final Color color;
  final bool initValue;
  final Widget child;
  final double size;
  final bool right;
  final Function(bool) onChange;
  CircleCheckBox(this.onChange, {this.initValue = false, this.right = true,
    this.color = Colors.red, this.child, this.size = 20 });

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

class _CircleCheckBoxState extends State<CircleCheckBox> {
  bool selected = false;

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    selected = widget.initValue;
    return InkWell(
      onTap: () {
        setState(() {
          selected = !selected;
        });
        widget.onChange(selected);
      },
      highlightColor: Colors.transparent,
      child: widget.right ? Row(
        children: [
          widget.child == null ? Container() : widget.child,
          Container(
            alignment: Alignment.center,
            margin: EdgeInsets.only(left: 6.px),
            child: selected ? Icon(IconFonts.done, size:
            widget.size, color: widget.color) : Icon(
                Icons.radio_button_off, size: widget.size, color: widget.color),
          )
        ],
      ) : Row(
        children: [
          Container(
            alignment: Alignment.center,
            margin: EdgeInsets.only(right: 6.px),
            child: selected ? Icon(IconFonts.done, size:
            widget.size, color: widget.color) : Icon(
                Icons.radio_button_off, size: widget.size, color: widget.color),
          ),
          widget.child == null ? Container() : widget.child,
        ],
      ),
    );
  }
}