Getting this error:
The setter ‘value=’ was called on null.
Receiver: null
Tried calling: value=3000.0
final WallheightController = TextEditingController();
final WalllengthController = TextEditingController();
var height;
var length;
var area;
RxDouble paint = 0.2.obs;
RxDouble result=0.0 .obs;
calculatepaint() {
if (WallheightController.text.isNotEmpty ||
WalllengthController.text.isNotEmpty ) {
height = double.parse(WallheightController.text);
length = double.parse(WalllengthController.text);
area.value = (height * length);
result.value = area.value* paint.value;
Get.toNamed(RoutesClass.prcalculation);
} else {
Get.snackbar("Fields empty", "Fill Required fields");
}
}
clear() {
WallheightController.clear();
WalllengthController.clear();
}
I am trying to calculate paint on an area of a wall but getting this error
2
Answers
make
var area = 0.0.obs;
you are using area.value so you need to make area .obs
I have gone through your and I have noticed something that I want to share with you.
You should always try to use variables with proper types like
double, int, String
and try to omit thevar
keyword as much as possible.When you are using GetX for your State Management solution, you can either make the variable reactive by .obs or you can set your variable as it. But whenever you want to reflect the changes in the UI you can call the
update()
method at the end of your task or function.Therefore there are mainly 2 answers to your question:
update()
method:If you are using second method, then don’t forget to Wrap your code with
GetBuilder
instead ofObx
.