El Hombre Sin Nombre
El Hombre Sin Nombre

Reputation: 3092

Flutter - Search elements in array with firstwhere

The problem is simple: What is the correct way to search element in array ?

My code is

data = [{id: 1, descripcion: Asier}, {id: 2, descripcion: Pepe}]
estateSelected= data.firstWhere((dropdown)=>dropdown.id==1);

The error that return is

Bad state: no element

Upvotes: 6

Views: 15145

Answers (1)

shadowsheep
shadowsheep

Reputation: 15012

You have some errors, this should work:

  var data = [{'id': 1, 'descripcion': 'Asier'}, {'id': 2, 'descripcion': 'Pepe'}];
  var estateSelected = data.firstWhere((dropdown) => dropdown['id'] == 1);
  print(estateSelected);

Fastest way to try is on dartpad

Upvotes: 15

Related Questions