Last active
September 2, 2021 14:59
-
-
Save yeasin50/eef18f25f6d9a489e70c5a8892fbfdce to your computer and use it in GitHub Desktop.
This file contains hidden or 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() { | |
final List<Map<String, Object>> perguntas = [ | |
{ | |
'texto': 'Qual é a sua cor favorita?', | |
'respostas': ['Preto', 'Vermelho', 'Verde', 'Branco'], | |
}, | |
{ | |
'texto': 'Qual é o seu animal favorito?', | |
'respostas': ['Coelho', 'Cobra', 'Elefante', 'Leão'], | |
}, | |
{ | |
'texto': 'Qual é o seu instrutor favorito?', | |
'respostas': ['Jacob', 'Rodrigo', 'Daniel', 'Leo'], | |
}, | |
]; | |
int? foundValueAt; | |
print(perguntas.length); | |
for (int i = 0; i < perguntas.length; i++) { | |
final items = perguntas[i]['respostas'] as List<String>; | |
// finding where `Elefante` contains | |
print(items.contains("Elefante") ? "YEs" : "NO"); | |
if (foundValueAt == null && items.contains("Elefante")) { | |
foundValueAt = i; | |
///finding index of `Elefante` inside of list<String> | |
final index = items.indexWhere((element) => element == 'Elefante'); | |
print("index of Elefante => $index"); | |
///let's change the value | |
perguntas[i]['respostas'] = items | |
..removeAt(index) | |
..add("newValue"); | |
} | |
} | |
print('Elefante found onMainList: index $foundValueAt'); | |
print("new Value>> "); | |
perguntas.forEach((e) { | |
print(e.toString()); | |
}); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Result