You will see what I want is to call the variable of my provider, which in this case is:
Icon _hearticon = const Icon(
Icons.favorite_border,
);
and also the method that changes the shape of the icon when pressed.
void changeHeart() {
if (_hearticon.icon == Icons.favorite_border) {
_hearticon = const Icon(
Icons.favorite,
);
} else {
_hearticon = const Icon(
Icons.favorite_border,
);
}
notifyListeners();
}
here the complete provider
import 'package:flutter/material.dart';
class HeartIconState with ChangeNotifier {
Icon _hearticon = const Icon(
Icons.favorite_border,
);
void changeHeart() {
if (_hearticon.icon == Icons.favorite_border) {
_hearticon = const Icon(
Icons.favorite,
);
} else {
_hearticon = const Icon(
Icons.favorite_border,
);
}
notifyListeners();
}
Icon get hearticon => _hearticon;
set hearticon(Icon value) {
_hearticon = value;
notifyListeners();
}
}
and the way I'm calling them:
IconButton(
icon: Heart.hearticon,
color: Colors.red,
iconSize: 25.0,
onPressed: Heart.changeHeart,
),
I had already done it like this when I was manipulating the state of a color to change from black to white and vice versa. I add the errors here. I uploaded a photograph because there are many.