Avoid `print` calls in production code. (Documentation)

It is because of the flutter_lints package which is implicitly added to new projects created after Flutter 2.3.0.

You can use any of the following solutions.

  1. To remove the warning in that single line:

    // ignore: avoid_print
    print('Hello World');
    
  2. To remove the warning in that file

    // ignore_for_file: avoid_print
    print('Hello World');
    
  3. To remove the warning from the whole project.

    Open analysis_options.yaml file and add this linter rule:

    include: package:flutter_lints/flutter.yaml
    
    linter:
      rules:
        avoid_print: false
    

Why not debugPrint or log?

Although you can also use debugPrint, or log (from dart:developer), but there are a few reasons why I don’t like them.

  1. They both work only in Flutter apps (not Dart apps)
  2. You’ll have to manually import a library for them to work (importing is such a pain unless imports on fly is implemented in IDE)
  3. They accept only a String as an argument, unlike print which accepts an Object? (everything)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)