[ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: Bad state: No element
在调用List.first 时报出该异常
看一下List 中get first方法的源码:
/*** Returns the first element.** Throws a [StateError] if `this` is empty.* Otherwise returns the first element in the iteration order,* equivalent to `this.elementAt(0)`.*/E get first {Iterator it = iterator;if (!it.moveNext()) {throw IterableElementError.noElement();}return it.current;}
通过源码可以看到在集合为空的时候会抛出一个异常, No element,
所以在调用List.first时,需要先判断list是否为空
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
