我有一个问题:(我有一个带有文本小部件的详细信息表单,我正在从我的数据库中获取值。我有一个带有控制器的 TextFormField,因为我需要设置实际价格,提交后,新值将在TextValueField,但我希望它显示在普通的文本小部件上。
我希望你能理解我的问题。但这里是我的代码
TextField(
decoration: InputDecoration(labelText: 'actual cost'),
controller: _profitController,
keyboardType:
TextInputType.numberWithOptions(decimal: true),
onSubmitted: (val) {
double amount =
double.parse(selectedEntry.amount); // 1 value
double aktPrice =
double.parse(val); // 2 value from this textfield
double profit = aktPrice * amount; // calc
_endProfitController.text = profit.toString();
newProfit = profit;
},
),
TextFormField(
readOnly: true,
decoration: InputDecoration(labelText: "profit"),
controller:
_endProfitController, //this is getting updated with the controller
textAlign: TextAlign.left,
style: TextStyle(
fontSize: 20,
color: Colors.grey[700],
),
),
Text(
'test profit: ' +
_endProfitController.text.toString() + newProfit.toString() +
' €', // this is not getting updated, and newProfit says "Null"...
textAlign: TextAlign.left,
style: TextStyle(
fontSize: 20,
color: Colors.grey[700],
),
),
好吧,我怎样才能在我的文本小部件中获取值?我试图在 onSubmitted 中设置状态,但控制器也没有更新。
我试图声明一个新的双 newProfit 但提交后它仍然给我空返回....
希望可以有人帮帮我 :)
最好的问候并感谢您的时间:)