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.
-
To remove the warning in that single line:
// ignore: avoid_print print('Hello World'); -
To remove the warning in that file
// ignore_for_file: avoid_print print('Hello World'); -
To remove the warning from the whole project.
Open
analysis_options.yamlfile 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.
- They both work only in Flutter apps (not Dart apps)
- 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)
- They accept only a
Stringas an argument, unlikeprintwhich accepts anObject?(everything)