I have a future bool method and i want to use this method IconButton color. If i use below codes, i see a error message on my device screen type'Future' is not a subtype of type 'bool' in type of cast.
Future<bool> ifExistInFavoriteList(String url) async {
bool ifExists = false;
SharedPreferences prefs = await SharedPreferences.getInstance(); List my = (prefs.getStringList('myFavoriteList') ?? List());
my.contains(url) ? ifExists = true : ifExists = false;
return ifExists;
}
bool _isLiked() {
bool a = false;
a = ifExistInFavoriteList(widget.imageUrl) as bool;
return a;
} }
Expanded(
child: IconButton(
color:
_isLiked() ? Colors.deepPurple : Colors.green,
icon: Icon(Icons.category),
onPressed: () {
//TO-DO
},
),
)