Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable all Logs [debugPrint()] in release build in flutter?

I have installed a release build apk in the android device but if I connect that device to Android studio then I am able to see all Logs/debugPrint statements.

Is there any way to disable the all the logs ?

like image 827
Ajay Kumar Avatar asked Mar 25 '18 11:03

Ajay Kumar


2 Answers

I combined the accepted answer with the idea from here and used it main.dart to silence all debugPrint everywhere.

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()
  );
}
like image 136
Sebastian Avatar answered Oct 18 '22 23:10

Sebastian


You can assign a dummy function to the global debugPrint variable:

import 'package:flutter/material.dart';

main() {
  debugPrint = (String message, {int wrapWidth}) {};
}
like image 24
Günter Zöchbauer Avatar answered Oct 19 '22 00:10

Günter Zöchbauer