What is Flutter Lint? How to resolve lint error effectively? |
Every language has its own Linting rules and preferences based on the syntax of the language. Flutter also has some presets but they can be modified as per your requirements.
What is Linting?
The process of checking the source code for Styling errors and code formatting. It helps in identifying some mistakes in the code such as unused pieces of code, dead code, etc. I will be explaining the rules later in the article.
The tool used to analyze code for Linting is known as Lint or Linter.
Flutter provides a flutter_lints package preinstalled and ready to use when you create a Flutter project. It can be verified from pubspec.yaml file, at the root of the project, under dev_dependencies
Flutter Lints package in pubspec.yaml |
Types of Linting
- Errors: Common coding errors.
- Style: These rules focus on styles.
- Pub: These lints deal with pub related rules.
How to set Lint Rules for a Flutter Project:
Step 1: Create a Flutter Project
First of all create a Flutter project where we can test our newly set rules. Either open VS codes Command Palette by shortcut Ctrl+Shift+P and select `create project` oprion or use terminal command `flutter create project_name`.
Step 2: Add some of the linting rules:
How to resolve them:
You can resolve most of the lint errors by modifying your Visual Studio Code settings file.
Goto settings.json file. To do so, open Command Palette by shortcut Ctrl+Shift+P and selecting Open User Setting (JSON).
Update the dart section as the following in the settings.json file:
settings.json my settings for dart |
You can read about effective dart styling here.
Do follow for more articles. Find me on any of the platforms mentioned on linktree.
0 Comments