Skip to content

Instantly share code, notes, and snippets.

@antklim
Created November 11, 2020 05:00
Show Gist options
  • Select an option

  • Save antklim/ecc439295db90313014a2ecc8072997a to your computer and use it in GitHub Desktop.

Select an option

Save antklim/ecc439295db90313014a2ecc8072997a to your computer and use it in GitHub Desktop.
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