I need to clean my code and for better coding style i need to pass a value to function and call the result this is my code looks like now
if (snapshot.hasData) {
print('Result: ${snapshot.data}');
double percentage1Calculate() {
int wouldClick = snapshot.data[index].wouldClick;
int ratherClick = snapshot.data[index].ratherClick;
double percentage1 = wouldClick / (wouldClick + ratherClick) * 100;
return percentage1;
}
double percentage2Calculate() {
int wouldClick = snapshot.data[index].wouldClick;
int ratherClick = snapshot.data[index].ratherClick;
double percentage2 = ratherClick / (wouldClick + ratherClick) * 100;
return percentage2;
}
}
What i need to do is instead of writing whole function percentage1Calculate and percentage1Calculate2 here i need to just pass the values in a function
Like this
if (snapshot.hasData) {
print('Result: ${snapshot.data}');
double percentage1Calculate(
snapshot.data[index].wouldClick,
snapshot.data[index].ratherClick);
double percentage2Calculate(
snapshot.data[index].wouldClick,
snapshot.data[index].ratherClick);
}
And then in function i can get these values and use
double percentage1Calculate(receive, recive) {
int wouldClick = recive.wouldClick;
int ratherClick = recive.ratherClick;
double percentage1 = wouldClick / (wouldClick + ratherClick) * 100;
return percentage1;
}