Skip to content

Instantly share code, notes, and snippets.

@antklim
Created November 10, 2020 03:19
Show Gist options
  • Save antklim/f55fc658390671b8a401a2b89c4e8944 to your computer and use it in GitHub Desktop.
Save antklim/f55fc658390671b8a401a2b89c4e8944 to your computer and use it in GitHub Desktop.
class CalculatorState extends ChangeNotifier {
CalculatorUseCase _useCase;
CalculatorState() {
_useCase = CalculatorUseCase(
onMemoryChanged: onMemoryChanged,
onOperationChanged: onOperationChanged);
}
void onMemoryChanged() => notifyListeners();
void onOperationChanged() => notifyListeners();
void setOperation(Operation operation) => _useCase.setOperation(operation);
ValueChanged<String> setOperand(Operand operand) => (String v) {
var value = double.tryParse(v) ?? 0.0;
return _useCase.setOperand(operand)(value);
};
void fromMemory(Operand operand) => _useCase.fromMemory(operand);
void memorise() => _useCase.memorise();
void resetMemory() => _useCase.resetMemory();
num get memory => _useCase.memory;
Operation get operation => _useCase.operation;
num get value => _useCase.value;
String get format => _useCase.format;
num operandValue(Operand operand) => _useCase.operandValue(operand);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment