Skip to main content

avoid-mutable-rx-variables

added in: 1.23.0
🛠
Pro+

Warns when GetX Rx primitives are declared as mutable variables.

Declaring Rx primitives as mutable variables can lead to memory leaks when the variable gets reassigned and should be avoided.

Example

❌ Bad:

void fn() {
Rx<Null> rx = Rx<Null>(null); // LINT: Avoid declaring mutable Rx variables. Try making it final instead.
RxList<String> list = <String>[].obs; // LINT: Avoid declaring mutable Rx variables. Try making it final instead.
RxSet<String> set = <String>{}.obs; // LINT: Avoid declaring mutable Rx variables. Try making it final instead.
RxMap<String> map = <String, String>{}.obs; // LINT: Avoid declaring mutable Rx variables. Try making it final instead.
}

✅ Good:

void fn() {
final rx = Rx<Null>(null);
final list = <String>[].obs;
final set = <String>{}.obs;
final map = <String, String>{}.obs;
}