如何在发行曲线中禁用所有日志[debugprint()]



我已经在Android设备中安装了一个版本构建APK,但是如果我将该设备连接到Android Studio,那么我可以看到所有日志/debugprint语句。

有什么方法可以禁用所有日志?

我将所接受的答案与此处的想法结合在一起,并使用了它。

const bool isProduction = bool.fromEnvironment('dart.vm.product');
void main() {
  if (isProduction) {      
      // analyser does not like empty function body
      // debugPrint = (String message, {int wrapWidth}) {};
      // so i changed it to this:
      debugPrint = (String? message, {int? wrapWidth}) => null;
  } 
  runApp(
    MyApp()
  );
}

您可以将虚拟函数分配给全局debugPrint变量:

import 'package:flutter/material.dart';
main() {
  debugPrint = (String message, {int wrapWidth}) {};
}

带有最新的弹奏版本返回空函数的最新幻影版本不起作用。不建议返回null,应避免返回 - 如果使用,则标记为标签,void函数不应具有零返回。相反,空字符串不会引起任何问题,并且可以完美工作:

main() {
  debugPrint = (String? message, {int? wrapWidth}) => '';
}

最新更新