avoid-read-inside-build
added in: 1.4.0
warning
Warns when a read
method is used inside of the build
method.
read
is designed to read the value one time which is, if done inside the build
method, can lead to missing the event when the provided value changes.
Example
❌ Bad:
class MyHomePage extends StatelessWidget {
const MyHomePage();
Widget build(BuildContext context) {
final value = context.read<int>(); // LINT
return Scaffold(
...
);
}
}
✅ Good:
class MyHomePage extends StatelessWidget {
const MyHomePage();
Widget build(BuildContext context) {
final value = context.watch<int>(); // LINT
return Scaffold(
...
);
}
}