Mauvais état: aucun élément
Sep 23 2020
je veux juste savoir à quoi ça sert? et quand il arrive, est-ce un problème d'API?
BlocBuilder<OrderBloc, OrderState>(
builder: (context, finalstate) {
if (state is OrderLoaded) {
for (var item in state.orderSent) {
totalweightsforsent.add(item.totalWeight);
//right here when i fetch the data from API and when it is done it is not going forward anymore
}
for (var item in state.orderPackaging) {
totalforpacking.add(item.totalWeight);
}
Réponses
3 jitsm555 Sep 23 2020 at 20:33
Non, ce n'est pas un problème d'API, c'est là pour une raison quelconque
Regardons l'exemple firstWheredont obtient la chaîne de couleur de la liste
Chaîne de couleurs InValid
void main() {
List<String> list = ['red', 'yellow', 'pink', 'blue'];
var newList = list.firstWhere((element) => element.contains('green'),
orElse: () => 'No matching color found');
print(newList);
}
Production:
Aucune couleur correspondante trouvée
Chaîne de couleur valide
void main() {
List<String> list = ['red', 'yellow', 'pink', 'blue'];
var newList = list.firstWhere((element) => element.contains('blue'),
orElse: () => 'No matching color found');
print(newList);
}
Production:
bleu
Ci-dessus, tous sont des cas valides mais si un orElse()bloc y manque, il jetteraBadStateException
void main() {
List<String> list = ['red', 'yellow', 'pink', 'blue'];
var newList = list.firstWhere((element) => element.contains('green'));
print(newList);
}
Production:
[VERBOSE-2: ui_dart_state.cc (171)] Exception non gérée: état incorrect: aucun élément