import 'package:flutter/material.dart';
import '../../../themes/app_dimension.dart';

import '../../../themes/app_colors.dart';
import '../../../themes/styles_text.dart';

class CheckboxWidget extends StatefulWidget {
  final String title;
  final bool isChecked;
  final Function(bool) onChange;
  final TextStyle? style;
  const CheckboxWidget({
    Key? key,
    required this.title,
    required this.isChecked,
    required this.onChange,
    this.style,
  }) : super(key: key);

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

class _CheckboxWidgetState extends State<CheckboxWidget> {
  var checked = false;

  @override
  void initState() {
    super.initState();
    checked = widget.isChecked;
  }

  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: () {
        setState(() {
          checked = !checked;
          widget.onChange(checked);
        });
      },
      child: Row(
        children: [
          checked
              ? Icon(
                  Icons.check_box,
                  color: AppColors.primary1,
                )
              : Icon(
                  Icons.check_box_outline_blank,
                  color: AppColors.neutral1,
                ),
          SizedBox(
            width: 8.w,
          ),
          Text(
            '${widget.title}',
            style: widget.style ?? StylesText.body1,
          ),
        ],
      ),
    );
  }
}
