prefer-bloc-extensions
- Group
- Style
- Path
lint/style/prefer-bloc-extensions- Default
- Off, opt in
- Origin
- Falcon
- Domain
- bloc
- Rule
- 319 of 512
Prefer context.read/watch over package:flutter_bloc's provider lookups.
Invalid
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_bloc/flutter_bloc.dart' as fb;
void example(Object context) {
BlocProvider.of<int>(context);
BlocProvider.of<int>(context, listen: false);
BlocProvider.of<int>(context, listen: true);
fb.BlocProvider.of<int>(context);
RepositoryProvider.of<int>(context);
}void example(Object context) { BlocProvider.of<int>(context); BlocProvider.of<int>(context); BlocProvider.of<int>(context, listen: false); BlocProvider.of<int>(context, listen: false); BlocProvider.of<int>(context, listen: true); BlocProvider.of<int>(context, listen: true); fb.BlocProvider.of<int>(context); fb.BlocProvider.of<int>(context); RepositoryProvider.of<int>(context);Valid
import 'package:flutter_bloc/flutter_bloc.dart' as fb;
class BlocProvider { static int of(Object context) => 0; }
class Custom { int of(Object context) => 0; }
void example(Object context, Custom service, Custom BlocProvider, bool listen) {
BlocProvider.of(context);
service.of(context);
context.read<int>();
context.watch<int>();
fb.BlocProvider.of<int>(context, listen: listen);
}
extension LocalContext on Object {
T read<T>() => throw StateError('fixture');
T watch<T>() => throw StateError('fixture');
}Configure prefer-bloc-extensions
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"style": {
"prefer-bloc-extensions": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/style/prefer-bloc-extensions: <reason>More style rules
- prefer-bloc-state-suffixbloc
Enforce the package-confirmed Bloc convention.
- prefer-center-over-alignflutter
Prefers
Centerover anAlignwhose alignment is known to be centered. - prefer-collection-literals
prefer_collection_literalsrecommendedFlags no-argument collection constructor calls that a literal would express.
- prefer-commenting-analyzer-ignores
Require explanations for analyzer
ignore:andignore_for_file:comments. - prefer-const-constructors
prefer_const_constructorsPrefers
constwhen invoking aconstconstructor with constant arguments. - prefer-const-constructors-in-immutables
prefer_const_constructors_in_immutablesflutterPrefers
constconstructors in immutable classes and extension types. - prefer-const-declarations
prefer_const_declarationsrecommendedFlags
finaldeclarations whose initializers are all constant expressions. - prefer-const-literals-to-create-immutables
prefer_const_literals_to_create_immutablesPrefers
constlist, set, and map literals as arguments to constructors of@immutableclasses.