Skip to content

Instantly share code, notes, and snippets.

@antklim
Created November 4, 2020 07:27
Show Gist options
  • Save antklim/414a7a018961afb0cdffd797687a5c94 to your computer and use it in GitHub Desktop.
Save antklim/414a7a018961afb0cdffd797687a5c94 to your computer and use it in GitHub Desktop.
class _CalculatorInputState extends State<CalculatorInput> {
...
num get calculatorValue {
switch (operation) {
case Operation.addition:
return operandA + operandB;
case Operation.subtraction:
return operandA - operandB;
case Operation.multiplication:
return operandA * operandB;
case Operation.division:
return operandA / operandB;
case Operation.sqrt:
return sqrt(operandA);
default:
return 0;
}
}
String get calculatorFormat {
switch (operation) {
case Operation.addition:
return '$operandA + $operandB';
case Operation.subtraction:
return '$operandA - $operandB';
case Operation.multiplication:
return '$operandA * $operandB';
case Operation.division:
return '$operandA / $operandB';
case Operation.sqrt:
return 'sqrt($operandA)';
default:
return '';
}
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment