我只想知道那是为了什么?以及它何时会出现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 no going forward anymore
                      }
                      for (var item in state.orderPackaging) {
                        totalforpacking.add(item.totalWeight);
                      }

最佳答案

不,这不是API问题,出于某种原因存在
让我们看一下firstWhere的示例,该示例从列表中获取颜色字符串
无效的颜色字符串

void main() {
  List<String> list = ['red', 'yellow', 'pink', 'blue'];
  var newList = list.firstWhere((element) => element.contains('green'),
      orElse: () => 'No matching color found');
  print(newList);
}
输出:
找不到匹配的颜色
有效颜色字符串
 void main() {
      List<String> list = ['red', 'yellow', 'pink', 'blue'];
      var newList = list.firstWhere((element) => element.contains('blue'),
          orElse: () => 'No matching color found');
      print(newList);
    }
输出:
蓝色
上面都是有效的情况,但是如果orElse()块丢失了,它将抛出BadStateException
void main() {
  List<String> list = ['red', 'yellow', 'pink', 'blue'];
  var newList = list.firstWhere((element) => element.contains('green'));
  print(newList);
}
输出:
[VERBOSE-2:ui_dart_state.cc(171)]未处理的异常:错误状态:无元素

关于flutter - 错误状态:无元素,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/64028985/

10-09 12:45