Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 为什么控制台中不显示错误?_Flutter - Fatal编程技术网

Flutter 为什么控制台中不显示错误?

Flutter 为什么控制台中不显示错误?,flutter,Flutter,我有一个未来建设者 FutureBuilder<bool>( future: getFuture(), builder: (context, snapshot) { if (snapshot.hasData) { if (snapshot.data) { //Data is true and should show something } //Data is false and should show somethi

我有一个未来建设者

FutureBuilder<bool>(
  future: getFuture(),
  builder: (context, snapshot) {
    if (snapshot.hasData) {
      if (snapshot.data) {
        //Data is true and should show something
      }
      //Data is false and should show something
    }
    return CircularProgressIndicator();
  },
);

Future<bool> getFuture() async {
  var myList = [];
  //Intentionally makes an error
  if (myList.first == 'foo') {
    //This should no be fired
  }
  return true;
}
if (snapshot.hasError) {
  print(snapshot.error); //Output: Bad state: No element
  //Handle error
}
现在控制台输出

Bad state: No element
与之前相反,我现在通过控制台获得一些信息,但错误输出并没有那么有用。它没有告诉我错误发生在哪里,这使得调试更加困难。假设我有一个非常复杂的
getFuture()
方法,我需要花很长时间才能找到错误发生的地方


我是不是运气不好,这是控制台能给我的最好输出吗?或者有没有办法让控制台的错误输出更详细?

if(snapshot.hasError)返回文本('${snapshot.error}')
不是你要找的东西?“有人知道为什么控制台上没有显示错误吗?”-这是因为他们没有打印这里报告的
错误:-他们只是返回
AsyncSnapshot.withError
@Willlas显然这正是我所渴望的。但答案往往会引出新的问题。有关我的新问题,请参见编辑