error-handling - 禁用 Flutter 的“死机红屏”
问题描述
有没有办法禁用 Flutter 的“红屏死机”?我在调试期间不介意它,但它似乎也出现在生产版本中 - 我找不到任何关于如何禁用它的信息,或者我自己捕获错误。
我尝试用FlutterError.onError
and捕捉杂散错误runZoned(onError)
,但两者都没有阻止红屏的出现。
作为参考,我说的是这个屏幕:
解决方案
您可以覆盖 ErrorWidget.builder 方法。
我解决了这个问题。
・示例代码。
void main() {
ErrorWidget.builder = (FlutterErrorDetails details) => Container();
...
}
・默认代码
static ErrorWidgetBuilder builder = _defaultErrorWidgetBuilder;
我希望它的帮助。
2019 年 12 月 21 日更新
或更改 ErrorWidget backgroundColor 和 textStyle。
・示例代码
import 'dart:ui' as ui;
void main() {
RenderErrorBox.backgroundColor = Colors.transparent;
RenderErrorBox.textStyle = ui.TextStyle(color: Colors.transparent);
}
推荐阅读
- python - 错误:在 python 中使用 cx_oracle 的语法无效
- python - 过多的多处理管道()导致套接字客户端和破折号客户端之间的延迟
- kubernetes-ingress - 使用 kubernetes 入口控制器的 Kong 在命中 Kong 时总是返回“未能从 ring-balancer 获取对等点”
- spring-boot - java.lang.IllegalArgumentException : org.keycloak.adapters.springboot.KeycloakSpringBootProperties
- windows - GetADusers - 带有选定的字段
- r - 有没有办法使用 str_replace_all 替换字符串中的 '(素数)?
- r - 在 R 中的 data.table 中动态比较列
- java - 使用 Quarkus 手动登录用户
- r - 正则表达式模式在 grepl 而不是在 dir 中工作
- reactjs - 用户单击标记时如何弹出信息窗口?