Hibok
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

59 rader
1.3 KiB

  1. import 'package:flutter/material.dart';
  2. class IconToggle extends StatefulWidget {
  3. final IconData icon;
  4. final IconData activeIcon;
  5. final Color defaultColor;
  6. final Color activeColor;
  7. final bool isActive;
  8. final double size;
  9. final void Function(bool) onTap;
  10. IconToggle({
  11. Key key,
  12. this.icon,
  13. this.defaultColor,
  14. this.activeColor,
  15. this.onTap,
  16. this.isActive: false,
  17. this.activeIcon,
  18. this.size,
  19. }) : super(key: key);
  20. @override
  21. _IconToggleState createState() => _IconToggleState();
  22. }
  23. class _IconToggleState extends State<IconToggle> {
  24. bool isActive;
  25. @override
  26. void initState() {
  27. super.initState();
  28. isActive = widget.isActive;
  29. }
  30. @override
  31. Widget build(BuildContext context) {
  32. Color curColor = isActive ? widget.activeColor : widget.defaultColor;
  33. IconData curIcon = isActive ? widget.activeIcon : widget.icon;
  34. return InkWell(
  35. child: Container(
  36. padding: EdgeInsets.only(left: 15, right: 15, bottom: 15),
  37. child: Icon(
  38. curIcon,
  39. color: curColor,
  40. size: widget.size,
  41. )),
  42. onTap: () {
  43. setState(() {
  44. isActive = !isActive;
  45. widget.onTap(isActive);
  46. });
  47. },
  48. );
  49. }
  50. }