Skip to content

Instantly share code, notes, and snippets.

@antklim
Last active November 5, 2020 21:42
Show Gist options
  • Save antklim/c5f09a27be0ab8753f2d69cd04724632 to your computer and use it in GitHub Desktop.
Save antklim/c5f09a27be0ab8753f2d69cd04724632 to your computer and use it in GitHub Desktop.
class OperandInput extends StatefulWidget {
final String label;
final num initValue;
final num memory;
final ValueChanged<String> onChanged;
const OperandInput(
{Key key, this.label, this.initValue, this.memory, this.onChanged})
: super(key: key);
@override
_OperandInputState createState() => _OperandInputState();
}
class _OperandInputState extends State<OperandInput> {
TextEditingController controller;
@override
void initState() {
super.initState();
controller = TextEditingController(text: '${widget.initValue}');
}
void onFromMemory() {
if (widget.memory == null) return;
setState(() {
controller.text = '${widget.memory}';
});
widget.onChanged(controller.text);
}
@override
Widget build(BuildContext context) {
return Container(
child: Row(
children: <Widget>[
...
Flexible(
child: TextField(
...
controller: controller,
onChanged: widget.onChanged,
),
),
Padding(
child: RaisedButton(
...
onPressed: onFromMemory
),
),
],
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment