I have created a list of map of antigens(elements) and added some antigens into another list i.e. selected. I want the color of the list item to be red if it is contained in the selected list. But it doesn't show color change even on printing the selected items the antigen is present there.

import 'package:allerpath_app_new/controller/mulit_allergy_profile_controller.dart';
import 'package:allerpath_app_new/model/blood_antigens.dart';
import 'package:flutter/material.dart';
import 'package:get/get_core/src/get_main.dart';
import 'package:get/get_instance/src/extension_instance.dart';

class TestingMAP extends StatelessWidget {
  TestingMAP({Key? key}) : super(key: key);

  final controller = Get.put(MultiProfile());

  final BloodAntigens antigen = BloodAntigens();

  Widget build(BuildContext context) {
    List<dynamic> _namesList =
        controller.selectedAntigens.map((e) => e['name']).toList();
    return SafeArea(
        child: Scaffold(
      body: ListView.builder(
        itemCount: antigen.inhalantPanel.length,
        itemBuilder: (context, index) {
          var item = antigen.inhalantPanel[index];
          return Text(
            style: TextStyle(
              color: (_namesList.contains(item)) ? Colors.red : Colors.black,

I printed the list and if it is present or not

print((controller.selectedAntigens.contains(item)) ? '1' : '0');


[{name: STRAW DUST, value: 123}]

Model code

List<Map<String, dynamic>> inhalantPanel = [
    {'name': 'HOUSE DUST', 'value': 0.35},
    {'name': 'MIXED MITES', 'value': 0.35},
    {'name': 'COCKROACH', 'value': 0.35},
    {'name': 'STRAW DUST', 'value': 0.35},
    {'name': 'COTTON', 'value': 0.35},
    {'name': 'JUTE', 'value': 0.35},

Solution 1: Huthaifa Muayyad

Because you probably don't have equality operators in your model of antigens.

You either do that, or create a list containing the names of antigens for example.

List<String> _namesList = controller.selectedAntigens.map((e)=>e['name']).toList();

print(_namesList.contains(item['name']) ? '1' : '0'); //=> "1";