I am trying to run an if-else condition that displays certain Icons based on the given conditions. I am trying to see if a particular quizId,i.e. a string is present inside the list to fulfill the condition. For some reason, the condition doesn't seem to work even though the element is present inside the list.
I have tried manually comparing the quizId with a particular String, which worked out fine. But as soon as I bring the list into the condition, it stops working. I have found both the quizId and List element data types which is String yet they still can't be compared.
This is the piece of Code :
class QuizBadge extends StatelessWidget {
const QuizBadge({super.key, required this.topic, required this.quizId});
final Topic topic;
final String quizId;
@override
Widget build(BuildContext context) {
Report report = Provider.of<Report>(context);
List completed = report.topics.values.toList();
List a = completed.expand((element) => element).toList();
print(a[1]);
if (a[1] == "flutter-basics") {
return const Icon(FontAwesomeIcons.checkDouble, color: Colors.green);
} else {
return const Icon(FontAwesomeIcons.solidCircle, color: Colors.grey);
}
}
}
Any help would be appreciated. Thank You.
Edited Code Piece :
Widget build(BuildContext context) {
Report report = Provider.of<Report>(context);
List completed = report.topics[topic.id] ?? [];
String str = completed.map((e) => e.toString()).join('-');
if (str.contains(quizId)) {
return const Icon(FontAwesomeIcons.checkDouble, color: Colors.green);
} else {
return const Icon(FontAwesomeIcons.solidCircle, color: Colors.grey);
}
}
This seems to be working.