Skip to main content

avoid-getx-rx-inside-build

Warns when GetX Rx primitives are instantiated inside the build method.

Instantiating Rx primitives inside the build method can lead to memory leaks as they will be recreated on every rebuild.

Example

❌ Bad:

class _SomeState extends State<Some> {

Widget build(BuildContext context) {
// LINT: Avoid using '.obs' or instantiating Rx primitives inside the 'build' method.
final count = 0.obs;

...
}
}

✅ Good:

class _SomeState extends State<Some> {
final count = 0.obs; // Correct, used as a field


Widget build(BuildContext context) {
...
}
}