问问题
14 次
1 回答
0
I would use ValueNotifier for this. But first you need to add a controller to your TextFormField
so you can get the text user typed in.
//initialize it
final myController = TextEditingController();
TextFormField(
controller: myController, //pass it to the TextFormField
),
TextButton(
child: new Text("ok"),
onPressed: () {
String input = myController.text; //this is how you get the text input
_formKey.currentState?.save();
Navigator.of(context).pop();
},
),
As I said you also need to initialize ValueNotifier and pass it to _showMessageDialog
ValueNotifier<int> money = ValueNotifier(0);
_showMessageDialog(money); //and pass it to your function
void _showMessageDialog(ValueNotifier<int> money) {
TextButton(
child: new Text("ok"),
onPressed: () {
String input = myController.text; //this is how you get the text input
money.value = int.parse(input); //and then update your money variable
_formKey.currentState?.save();
Navigator.of(context).pop();
},
),
}
于 2022-02-19T16:24:34.163 回答