This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OperandInput extends StatefulWidget { | |
final String label; | |
final num initValue; | |
final num memory; | |
final ValueChanged<String> onChanged; | |
const OperandInput( | |
{Key key, this.label, this.initValue, this.memory, this.onChanged}) | |
: super(key: key); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CalculusScreen extends StatefulWidget { | |
@override | |
_CalculusScreenState createState() => _CalculusScreenState(); | |
} | |
class _CalculusScreenState extends State<CalculusScreen> { | |
num memory; | |
num calculatorResult; // current operation result | |
void onMemorise() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class _CalculusScreenState extends State<CalculusScreen> { | |
... | |
void onCalulatorResultChanged(num value) { | |
setState(() { | |
calculatorValue = value; | |
}); | |
} | |
@override |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class _CalculatorInputState extends State<CalculatorInput> { | |
final operations = <Operation, String>{ | |
Operation.addition: 'Addition', | |
... | |
}; | |
Operation operation = Operation.addition; | |
num operandA = 0; | |
num operandB = 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Operation { addition, subtraction, division, multiplication, sqrt } | |
enum Operand { A, B } | |
class CalculatorUseCase { | |
num memory; | |
Operation operation; | |
num operandA; | |
num operandB; | |
CalculatorUseCase( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
group('Calculator use case', () { | |
group('calculates value of', () { | |
Map<CalculatorUseCase, num> testCases = { | |
CalculatorUseCase(operation: Operation.addition, operandA: 1, operandB: 2): 3, | |
... | |
}; | |
testCases.forEach((useCase, expected) { | |
test('${useCase.operation}', () { | |
expect(useCase.value, expected); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class _CalculusScreenState extends State<CalculusScreen> { | |
CalculatorUseCase useCase = CalculatorUseCase(); | |
void onMemorise() { | |
setState(() { | |
useCase.memorise(); | |
}); | |
} | |
void onResetMemory() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CalculatorInput extends StatefulWidget { | |
final CalculatorUseCase useCase; | |
const CalculatorInput({Key key, this.useCase}) : super(key: key); | |
@override | |
_CalculatorInputState createState() => _CalculatorInputState(); | |
} | |
class _CalculatorInputState extends State<CalculatorInput> { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OperandInput extends StatefulWidget { | |
final String label; | |
final Operand operand; | |
final CalculatorUseCase useCase; | |
final Function onChanged; | |
const OperandInput({Key key, this.label, this.operand, this.useCase, this.onChanged}) : super(key: key); | |
@override | |
_OperandInputState createState() => _OperandInputState(); |