Created
November 3, 2020 02:02
-
-
Save antklim/bec52eb2d4b31e780574025b32b91e86 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
| enum Operation { addition, subtraction, division, multiplication, sqrt } | |
| class CalculatorInput extends StatefulWidget { | |
| @override | |
| _CalculatorInputState createState() => _CalculatorInputState(); | |
| } | |
| class _CalculatorInputState extends State<CalculatorInput> { | |
| final operations = <Operation, String>{ | |
| Operation.addition: 'Addition', | |
| ... | |
| }; | |
| Operation operation = Operation.addition; | |
| void onOperationChanged(Operation newOperation) { | |
| setState(() { | |
| operation = newOperation; | |
| }); | |
| } | |
| @override | |
| Widget build(BuildContext context) { | |
| return Container( | |
| margin: const EdgeInsets.only(top: 10), | |
| child: Column( | |
| children: <Widget>[ | |
| Row( | |
| mainAxisAlignment: MainAxisAlignment.spaceBetween, | |
| children: <Widget>[ | |
| Text('Operation', style: Theme.of(context).textTheme.bodyText2), | |
| DropdownButton( | |
| value: operation, | |
| items: operations.entries | |
| .map((entry) => DropdownMenuItem( | |
| child: Text(entry.value), value: entry.key)) | |
| .toList(), | |
| onChanged: onOperationChanged, | |
| ), | |
| ], | |
| ), | |
| Operand(label: 'Operand A', initValue: 0), | |
| operation == Operation.sqrt | |
| ? SizedBox(height: 68) | |
| : Operand(label: 'Operand B', initValue: 0), | |
| Container( | |
| margin: const EdgeInsets.only(top: 10, bottom: 20), | |
| child: Text('0 + 0 = 0.000')), | |
| ], | |
| ), | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment