AvoidDirectMethodChannel class

禁止业务代码直接实例化 MethodChannelEventChannel

原因:

  • 没有统一的错误语义(PlatformExceptionAppException 转换缺失);
  • 没有 channel 名称注册中心,容易 typo;
  • 测试时无法按 method 粒度 mock,只能全局 setMockMethodCallHandler
  • VM 直接触达原生层,违反分层——应该经 DataSource → Repository。

要求改用 ChannelClient(flutter_spine/network),或在此之上做一层 业务 ApiClient 封装;ViewModel 只调 Repository。

豁免

  • flutter_spine 的 ChannelClient 实现本身:package/flutter_spine/lib/src/network/**
  • 测试 / fixture / example 路径
  • 应用启动代码 /lib/main.dart / lib/bootstrap.dart

Constructors

AvoidDirectMethodChannel()
const

Properties

code → LintCode
The LintCode that this LintRule may emit.
finalinherited
enabledByDefault bool
Whether the lint rule is on or off by default in an empty analysis_options.yaml
no setterinherited
filesToAnalyze List<String>
A list of glob patterns matching the files that run cares about.
no setterinherited
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

getFixes() List<Fix>
Obtains the list of Fix associated with this LintRule.
inherited
isEnabled(CustomLintConfigs configs) bool
Checks whether this lint rule is enabled in a configuration file.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
run(CustomLintResolver resolver, ErrorReporter reporter, CustomLintContext context) → void
Emits lints for a given file.
startUp(CustomLintResolver resolver, CustomLintContext context) Future<void>
Emits lints for a given file.
inherited
testAnalyzeAndRun(File file) Future<List<AnalysisError>>
Analyze a Dart file and runs this assist in test mode.
inherited
testRun(ResolvedUnitResult result, {Pubspec? pubspec}) Future<List<AnalysisError>>
Runs this assist in test mode.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited