import 'package:flutter/material.dart';

class IconToggle extends StatefulWidget {
  final IconData icon;
  final IconData activeIcon;

  final Color defaultColor;
  final Color activeColor;
  final bool isActive;

  final double size;
  final void Function(bool) onTap;

  IconToggle({
    Key key,
    this.icon,
    this.defaultColor,
    this.activeColor,
    this.onTap,
    this.isActive: false,
    this.activeIcon,
    this.size,
  }) : super(key: key);

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

class _IconToggleState extends State<IconToggle> {
  bool isActive;

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

  @override
  Widget build(BuildContext context) {
    Color curColor = isActive ? widget.activeColor : widget.defaultColor;
    IconData curIcon = isActive ? widget.activeIcon : widget.icon;
    return InkWell(
      child: Container(
          padding: EdgeInsets.only(left: 15, right: 15, bottom: 15),
          child: Icon(
            curIcon,
            color: curColor,
            size: widget.size,
          )),
      onTap: () {
        setState(() {
          isActive = !isActive;
          widget.onTap(isActive);
        });
      },
    );
  }
}
