Saltearse al contenido

Linter Configuration

Esta página aún no está disponible en tu idioma.

By default, the bloc linter will not report any diagnostics unless you have explicitly configured a project’s analysis options.

To get started, create or modify the existing analysis_options.yaml at the root of your project to include a list of rules under the top-level bloc key:

analysis_options.yaml
bloc:
rules:
- avoid_flutter_imports

Run the linter using the following command in your terminal:

Ventana de terminal
bloc lint .

The above command will analyze all files in the current directory and its subdirectories, but you can also lint specific files and directories by passing them as command-line arguments:

Ventana de terminal
bloc lint src/ test/

The above command will analyze all code in the src and test directories.

If the avoid_flutter_imports rule is enabled, any bloc or cubit file that contains a flutter import will be reported as a warning:

counter_cubit.dart
import 'package:bloc/bloc.dart';
import 'packages:flutter/material.dart';
class CounterCubit extends Cubit<int> {
CounterCubit() : super(0);
}

You can see the warning by running the bloc lint command:

Ventana de terminal
bloc lint counter_cubit.dart

The output should look like:

Ventana de terminal
warning[avoid_flutter_imports]: Avoid importing Flutter within bloc instances.
--> counter_cubit.dart:2
|
| import 'package:flutter/material.dart';
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= hint: Blocs should be decoupled from Flutter.
docs: https://bloclibrary.dev/lint-rules/avoid_flutter_imports
1 issue found
Analyzed 1 file