Avoid Flutter Imports
Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.
Avoid introducing dependencies on Flutter within business logic components
(Bloc
or Cubit
instances).
Rationale
Section titled “Rationale”Layering an application is a key part of building a maintainable codebase and helps developers iterate quickly and with confidence. Each layer should have a single responsibility and be able to function and tested in isolation. This allows you to contain changes to specific layers, minimizing the impact on the entire application.
As a result, business logic components should generally manage feature state and be decoupled from the UI layer. Events should flow into business logic components from the UI layer and state should flow out of the business logic layer into the UI layer.
Keeping business logic components decoupled from Flutter provides the ability to reuse business logic across multiple platforms/frameworks (e.g. Flutter, AngularDart, Jaspr, etc.).
Examples
Section titled “Examples”DO NOT import Flutter within your business logic components.
BAD:
import 'package:bloc/bloc.dart';
// Avoid depending on Flutter!// Prefer to keep business logic decoupled from the UI layer.import 'packages:flutter/material.dart';
class CounterCubit extends Cubit<int> { CounterCubit() : super(0);}
GOOD:
import 'package:bloc/bloc.dart';
class CounterCubit extends Cubit<int> { CounterCubit() : super(0);}
Enable
Section titled “Enable”To enable the avoid_flutter_imports
rule, add it to your
analysis_options.yaml
under bloc
> rules
:
bloc: rules: - avoid_flutter_imports
bloc: rules: avoid_flutter_imports: true