Skip to content

Instantly share code, notes, and snippets.

@antklim
Last active November 9, 2020 23:47
Show Gist options
  • Save antklim/38193d5e7d0ce62481c1651394acde2f to your computer and use it in GitHub Desktop.
Save antklim/38193d5e7d0ce62481c1651394acde2f to your computer and use it in GitHub Desktop.
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