Last active
November 5, 2020 21:42
-
-
Save antklim/c5f09a27be0ab8753f2d69cd04724632 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 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