AvoidStaticMutableInNotifier class

禁止在 Notifier / ViewModel 上声明 static 可变字段。

Riverpod 的 autoDispose / family / test override 都依赖"状态由 Notifier 实例 独占"的不变式——static 字段会跨实例共享,出现:

  • family key 切换后 page 仍读到旧页数据;
  • 测试 container 销毁后变量仍持有,下条测试读到脏数据;
  • 热重载不清零。

命中条件

同时满足:

  1. 类是 VM / Notifier(extends 或 with 任一):
    • ViewModelNotifier / FamilyViewModelNotifier
    • AsyncViewModelNotifier / FamilyAsyncViewModelNotifier
    • Notifier / AsyncNotifier / 它们的 auto-dispose / family 变体
  2. 字段声明是 static
  3. 字段不是 const不是 final(即可变)。

可变 static 字段中,唯一豁免的是 static conststatic final ——- 它们是只读全局常量,不会产生跨实例污染。

Constructors

AvoidStaticMutableInNotifier()
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