1
RxList<String> selectedMemberList = <String>[].obs;
selectedMemberList = [180,160,150]

I want to display text in red color if ID contains in selectedMemberList.

So, I simply called,

if selectedMemberList.contains('180'){
text in red color
}else{
text in black color}

but, I got text in black color every time. That means ID doesnt matched. How do I match member ID to given selectedMemberList.

2 Answers 2

1

if your items are in a single string separated by a comma, first convert that into a list like this :

String collectedIds = "180,160,150";
final split = tagName.split(',');
final Map<int, String>  selectedMemberList= {
  for (int i = 0; i < split.length; i++)
    i: split[i]
};

and now you can check the condition :

if selectedMemberList.contains('180'){
text in red color
}else{
text in black color}

Hope this will help you.

Sign up to request clarification or add additional context in comments.

2 Comments

String collectedIds = 180,160,150; selectedMemberList.add(collectedIds); So, Problem is here, comma separated strings are not converting in list as an Item. here is total 3 IDs in string when i converting in list, selectedMemberList length is only one instead of 3. can you help me in conversion of string to stringlist ?
I did this way. an it is solved
0

Here is a cleaner way on checking if value exist on a list.

RxList<String> selectedMemberList = <String>[].obs;
selectedMemberList = ["160","180","150"];
  
  
if (selectedMemberList.where((item) => item == "180").isNotEmpty){
  text in red color
} else {
  text in black color
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.