avoid-bloc-public-methods

Group
Style
Path
lint/style/avoid-bloc-public-methods
Default
Off, opt in
Origin
Falcon
Domain
bloc
Rule
24 of 512
bloc

Enforce the package-confirmed Bloc convention.

Invalid

example.dartdart
import 'package:bloc/bloc.dart';
class Example extends Bloc<int, int> {
  Example() : super(0);
  void command0() {}
  void command1() {}
  void command2() {}
  void command3() {}
  void command4() {}
}
Keep Bloc command methods private; expose events instead.
3 Example() : super(0);
4 void command0() {}
Keep Bloc command methods private; expose events instead.
4 void command0() {}
5 void command1() {}
Keep Bloc command methods private; expose events instead.
5 void command1() {}
6 void command2() {}
Keep Bloc command methods private; expose events instead.
6 void command2() {}
7 void command3() {}
Keep Bloc command methods private; expose events instead.
7 void command3() {}
8 void command4() {}

Valid

example.dartdart
import 'package:bloc/bloc.dart';
class Example extends Bloc<int, int> {
  Example() : super(0);
  void _command() {}
  static void shared() {}
  int get value => 1;
  @override Future<void> close() async {}
  @override void add(int event) {}
}
class Counter extends Cubit<int> { Counter() : super(0); void increment() {} }
class Ordinary { void command() {} }

Configure avoid-bloc-public-methods

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

falcon.jsonjson
{
  "linter": {
    "rules": {
      "style": {
        "avoid-bloc-public-methods": "error"
      }
    }
  }
}

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

example.dartdart
// falcon-ignore lint/style/avoid-bloc-public-methods: <reason>