Skip to content

filtrar no dart #41

Sep 26, 2022 · 2 comments · 4 replies
Discussion options

You must be logged in to vote

Olá @Lanysc, você pode fazer assim:

class myObj {
  final String name;
  final List<String> team;
  
  myObj ({
    required this.name,
    required this.team,
  });
}

void main() {
 List<myObj> obj = [
    myObj(name: "Name 1", team: ['1', '2']),
    myObj(name: "Name 2", team: ['2']),
    myObj(name: "Name 3", team: ['3']),
  ];
  
  List<String> filtersTeams = ['1', '3'];
  
  List<myObj> filteredList = [];
  
  for (var item in obj) {
    if (item.team.any((team) => filtersTeams.contains(team))) {
      filteredList.add(item);
    }
  }
 
  filteredList.forEach((e) => print(e.name));
}

O seu exemplo não está dando certo, pois contains verifica se uma lista contém um elemento e não um…

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
3 replies
@Lanysc
Comment options

@Lanysc
Comment options

@fredfv
Comment options

Comment options

You must be logged in to vote
1 reply
@Zeca-dev
Comment options

Answer selected by Lanysc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
5 participants