Last active
June 10, 2019 11:35
-
-
Save luizjacomn/5009b61d6b2b34e1dd0ecc16903c0461 to your computer and use it in GitHub Desktop.
Testando relação entre categoria e itens
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main(){ | |
Categoria cat1 = Categoria(1); | |
List<Item> itens = [ | |
Item(id: 1, completado: false, obrigatorio: false), | |
Item(id: 2, completado: true, obrigatorio: true), | |
Item(id: 3, completado: true, obrigatorio: true), | |
Item(id: 4, completado: true, obrigatorio: false), | |
Item(id: 5, completado: true, obrigatorio: true), | |
]; | |
cat1.itens = itens; | |
cat1.itens[0].respostas = {'tempo_evento': 0, 'periodo':5,}; | |
print(cat1.isAllObrigatoriosPreenchidos()); | |
print(Map.fromIterable(cat1.itens, key: (item)=>item.id, value: (item)=> item.toMap())); | |
} | |
class Item { | |
int id; | |
bool obrigatorio = false; | |
bool completado = false; | |
Map<String, dynamic> respostas = Map(); | |
Item({this.id, this.completado, this.obrigatorio}); | |
Map<String, dynamic> toMap() { | |
return { | |
'obrigatorio':obrigatorio, | |
'completado':completado, | |
if(respostas.isNotEmpty) | |
'respostas':respostas, | |
}; | |
} | |
} | |
class Categoria { | |
int id; | |
List<Item> itens; | |
Categoria(this.id); | |
bool isAllObrigatoriosPreenchidos() => | |
itens.where((item) => item.obrigatorio).every((item) => item.completado); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment