I am a Beginner and I want to calculate 4 values and get area but I keep getting different
errors my code is not good so please give advices
Like:
Class ‘String’ has no instance method ‘/’.
Receiver: "56"
Tried calling: /(2)
I am taking values from text fields
I want them to be calculated in double.
This is My Code
class SideController extends GetxController{
final SideAController = TextEditingController();
final SideBController = TextEditingController();
final SideCController = TextEditingController();
final SideDController = TextEditingController();
var Result=''.obs;
var sidea;
var sideb;
var sidec;
var sided;
var length;
var width;
var area = 0.obs;
calculateheight() {
if (SideAController.text != null ||
SideBController.text != null ||
SideCController.text != null ||
SideDController.text != null) {
sidea = SideAController.text;
sideb = SideBController.text;
sidec = SideCController.text;
sided = SideDController.text;
length = ((sidea) + (sidec)) / 2;
width = ((sideb) + (sided)) / 2;
area = (length * width);
area.value == Result;
return area;
} else {
Get.snackbar("Fields Empty", "Fill all Fields");
}
}
}
I tried to calculate 4 values and show my result is string
but keep getting errors
2
Answers
String
values cannot be added or divided. You have to convert theString
values todouble
first.If you want to return area as String, use
return area.toString();
I think there are already variables here. I write down what I already know.
For example, there is Result=”.obs;
I checked the code I posted, the code I posted should work for you.
Optionally, calculateheight() function can return String, double, etc.