Last active
November 9, 2020 23:47
-
-
Save antklim/38193d5e7d0ce62481c1651394acde2f to your computer and use it in GitHub Desktop.
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> { | |
... | |
void onOperationChanged(Operation newOperation) { | |
widget.useCase.setOperation(newOperation); | |
setState(() {}); | |
} | |
void onOperandChanged() { | |
// rebuilding calculation result widget | |
setState(() {}); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Container( | |
child: Column( | |
children: <Widget>[ | |
Row( | |
children: <Widget>[ | |
DropdownButton( | |
... | |
value: widget.useCase.operation, | |
onChanged: onOperationChanged, | |
), | |
], | |
), | |
OperandInput( | |
label: 'Operand A', | |
operand: Operand.A, | |
useCase: widget.useCase, | |
onChanged: onOperandChanged), | |
widget.useCase.operation == Operation.sqrt | |
? SizedBox(height: 68) | |
: OperandInput(label: 'Operand B', ...), | |
Container( | |
child: Text('${widget.useCase.format} = ${widget.useCase.value.toStringAsFixed(3)}')), | |
], | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment