Untitled

 avatar
unknown
dart
3 years ago
1.9 kB
5
Indexable
class CustomCheckbox extends StatefulWidget {
  const CustomCheckbox({
    Key? key,
    this.onChange,
    this.isChecked,
    this.size,
    this.iconSize,
    this.selectedColor,
    this.selectedIconColor,
    this.borderColor,
    this.checkIcon,
  }) : super(key: key);
  final Function? onChange;
  final bool? isChecked;
  final double? size;
  final double? iconSize;
  final Color? selectedColor;
  final Color? selectedIconColor;
  final Color? borderColor;
  final Widget? checkIcon;

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

class _CustomCheckboxState extends State<CustomCheckbox> {
  bool _isSelected = false;

  @override
  void initState() {
    _isSelected = widget.isChecked ?? false;
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    ThemeNotifier themeNotifier = Provider.of<ThemeNotifier>(
      context,
      listen: true,
    );
    return GestureDetector(
      onTap: () {
        setState(() {
          _isSelected = !_isSelected;
          widget.onChange!(_isSelected);
        });
      },
      child: AnimatedContainer(
        duration: const Duration(milliseconds: 500),
        curve: Curves.fastLinearToSlowEaseIn,
        decoration: BoxDecoration(
          color: Colors.transparent,
          borderRadius: BorderRadius.circular(6.0),
          border: Border.all(
            color: widget.borderColor ?? themeNotifier.getTheme().hoverColor,
            width: 1,
          ),
        ),
        width: widget.size ?? 25,
        height: widget.size ?? 25,
        child: _isSelected
            ? Icon(
                Icons.check,
                color: widget.selectedIconColor ??
                    themeNotifier.getTheme().hoverColor,
                size: widget.iconSize ?? 14,
              )
            : null,
      ),
    );
  }
}
Editor is loading...