i am implementing like unlike feature .so in my postman the response is
"like_status": "0",
"saved_post_status": "0"
String? likeStatusmodel;
String? savedPostStatus;
My Modeldatatype i used used is String? for both like_status & Saved_post_status ,as the returned data is in double quotes,
while loading some post its threw this exceptions as
type ‘int’ is not a subtype of type ‘String?’,,why this issue, how to solve
also is this check possible while using string
child: SvgPicture.asset(
color: (singleUserPost.postLikeCount ==
'0')
? Colors.black
: Colors.red,
fit: BoxFit.cover,
width: 20,
"assets/images/like.svg")),
while changing to
color: (singleUserPost.postLikeCount ==
0)
? Colors.black
: Colors.red,
fit: BoxFit.cover,
width: 20,
"assets/images/like.svg")),
showing this warning & also conditional check is not done
warning
Equality operator ==
invocation with references of unrelated types
3
Answers
Seems like
singleUserPost.postLikeCount
can be null and of typeString
. So need to parse that as int to compare.Can you try
Try this in dartpad
your first question
type ‘int’ is not a subtype of type ‘String?’,,why this issue, how to solve
solution: to solve this issue you print or log your variable by veriable.runtimeType this will show you data type of your variable.
example
Yes, you can compare string while using == operator .
example: