avoid-public-notifier-properties

Group
Style
Path
lint/style/avoid-public-notifier-properties
Default
Off, opt in
Origin
Falcon
Domain
riverpod
Rule
116 of 512
riverpod

Keeps notifier state behind Riverpod's observable state property.

Invalid

example.dartdart
import 'package:riverpod/riverpod.dart';
abstract class Counter extends Notifier<int> {
  int count = 0;
  final int initial = 0;
  int get current => count;
  set current(int value) { count = value; }
}
abstract class AsyncCounter extends AsyncNotifier<int> {
  int cached = 0;
}
abstract class Derived extends Counter {
  int extra = 0;
}
Expose notifier data through state rather than a public property.
2abstract class Counter extends Notifier<int> {
3 int count = 0;
Expose notifier data through state rather than a public property.
3 int count = 0;
4 final int initial = 0;
Expose notifier data through state rather than a public property.
4 final int initial = 0;
5 int get current => count;
Expose notifier data through state rather than a public property.
5 int get current => count;
6 set current(int value) { count = value; }
Expose notifier data through state rather than a public property.
8abstract class AsyncCounter extends AsyncNotifier<int> {
9 int cached = 0;
Expose notifier data through state rather than a public property.
11abstract class Derived extends Counter {
12 int extra = 0;

Valid

example.dartdart
import 'package:riverpod/riverpod.dart' as rp;
abstract class Good extends rp.Notifier<int> {
  int _count = 0;
  int get _current => _count;
  set _current(int value) { _count = value; }
  static int cache = 0;
  int build() => _count;
  void increment() { state = state + 1; }
}
class Notifier<T> {}
class Unrelated extends Notifier<int> { int publicValue = 0; }
class Plain { int value = 0; int get other => value; }

Configure avoid-public-notifier-properties

Set its severity in falcon.json. See the configuration guide.

falcon.jsonjson
{
  "linter": {
    "rules": {
      "style": {
        "avoid-public-notifier-properties": "error"
      }
    }
  }
}

Or silence one occurrence with a suppression comment; the reason is required.

example.dartdart
// falcon-ignore lint/style/avoid-public-notifier-properties: <reason>