当前位置: 代码迷 >> 综合 >> Flutter 捕获异常
  详细解决方案

Flutter 捕获异常

热度:73   发布时间:2023-12-08 18:17:56.0
FlutterBugly.postCatchedException((){false;runZonedGuarded(() { runApp(MyApp()); }, reportError);
});???????void reportError(Object, StackTrace) async {// print('收集到错误: $Object, $StackTrace');var path = await getFilePath('error');var name = utils.CustomStampToTime_str(Date: '${userInfo.userid}@YY.MM.DD');var _has = await checkCache('$name', file: 'error');File _errFile = File('${path}/${name}');String errMsg = await readCache(name, type: 'error');errMsg += '\n==================';errMsg += '\n';errMsg += '时间:${utils.CustomStampToTime_str(Date: 'YY-MM-DD hh:mm:ss')}';errMsg += '\n';errMsg += '$Object';errMsg += '\n';errMsg += '$StackTrace';errMsg += '\n';await _errFile.writeAsString(errMsg);// print('完成');
}// 获取app临时文件路径
Future getFilePath(type) async{var filepath = await getApplicationDocumentsDirectory(); // App内部file:data.com.nufang.zao/app-flutter/// var filepath = await getTemporaryDirectory();        // App内部file:data.com.nufang.zao/ache/// var filepath = await getExternalStorageDirectory();  // App内部file:data.com.nufang.zao/file/var file;if(type == 'all'){file = Directory(filepath.path);}else{file = Directory(filepath.path + '/$type');}try {bool exists = await file.exists();if (!exists) {await file.create();}} catch (e) {print(e);}return file.path;
}