Skip to content

Instantly share code, notes, and snippets.

@luscas
Created October 4, 2022 20:53
Show Gist options
  • Save luscas/b042eba4304eb068af744ced3c754f43 to your computer and use it in GitHub Desktop.
Save luscas/b042eba4304eb068af744ced3c754f43 to your computer and use it in GitHub Desktop.
class Noticia {
String title;
DateTime createdAt;
Noticia(this.title, this.createdAt);
}
void main() {
List<Noticia> registers = [
Noticia("Primeira postagem", DateTime(2022,07,01)),
Noticia("Segunda postagem", DateTime(2022,11,01)),
];
Iterable<Noticia> esteAno = registers.where((Noticia item) {
return item.createdAt.year == DateTime.now().year;
});
Iterable<Noticia> esteMes = registers.where((Noticia item) {
return item.createdAt.year == DateTime.now().year && item.createdAt.month == DateTime.now().month;
});
print(esteMes.first.title);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment