Created
November 11, 2020 05:00
-
-
Save antklim/ecc439295db90313014a2ecc8072997a 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 StatelessWidget { // StatefulWidget replaced with StatelessWidget | |
| @override | |
| Widget build(BuildContext context) { | |
| CalculatorState state = Provider.of<CalculatorState>(context); | |
| final operations = <Operation>[Add, Sub, Mul, Div, Sqrt]; | |
| return Container( | |
| child: Column( | |
| children: <Widget>[ | |
| Row( | |
| children: <Widget>[ | |
| Text('Operation', style: Theme.of(context).textTheme.bodyText2), | |
| DropdownButton( | |
| value: state.operation, // values read directly from state | |
| items: operations | |
| .map((entry) => | |
| DropdownMenuItem(child: Text(entry.name), value: entry)) | |
| .toList(), | |
| onChanged: state.setOperation, | |
| ), | |
| ], | |
| ), | |
| OperandInput(label: 'Operand A', operand: Operand.A), | |
| state.operation == Sqrt | |
| ? SizedBox(height: 68) | |
| : OperandInput(label: 'Operand B', operand: Operand.B), | |
| Container( | |
| child: Text('${state.format} = ${state.value.toStringAsFixed(3)}')), | |
| ], | |
| ), | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment