0

Lets say I have these arrayed JSON values

[{operation_id: 2, operation_name: FAITHFUL BELIEVERS}, 
{operation_id: 3, operation_name: SAMPLE OP}, 
{operation_id: 4, operation_name: SAMPLE OP 2}]

Now I will select the operation name 'SAMPLE OP' but I want to display the value of its operation_id. How would I do that?

1 Answer 1

1

Your JSON is a list of maps, so use where on the list to filter it by your predicate. Better still, use firstWhere as we assume there's just one match.

The match function returns true if the operation name member of the map matches.

firstWhere returns the first matching map, and you want the operation id member of that map.

  final id = list
      .firstWhere((m) => m['operation_name'] == 'SAMPLE OP')['operation_id'];
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.