我正在嘗試在 Android Studio 中運行代碼,但總是在運行代碼時出現此錯誤:
錯誤:沒有名為“控制器”的命名引數。
TextEditingController nota1Controller = TextEditingController();
nota1Controller.text = "";
double nota1 = double.parse(nota1Controller.text);
TextField(
keyboardType: TextInputType.number,
decoration: InputDecoration(
labelText: "Nota 1",
labelStyle: TextStyle(color: Colors.green),
controller: nota1Controller,// <-- HERE IT'S THE "CONTROLLER"
),
textAlign: TextAlign.center,
style: TextStyle(color: Colors.green, fontSize: 25.0),
),
我瀏覽了很多網站,但我找不到解決方案
uj5u.com熱心網友回復:
您將控制器放在裝飾內,只需將其放在外面:
改變這個:
TextField(
keyboardType: TextInputType.number,
decoration: InputDecoration(
labelText: "Nota 1",
labelStyle: TextStyle(color: Colors.green),
controller: nota1Controller, <-- HERE IT'S THE "CONTROLLER"
),
textAlign: TextAlign.center,
style: TextStyle(color: Colors.green, fontSize: 25.0),
),
對此:
TextField(
controller: nota1Controller,
keyboardType: TextInputType.number,
decoration: InputDecoration(
labelText: "Nota 1",
labelStyle: TextStyle(color: Colors.green),
),
textAlign: TextAlign.center,
style: TextStyle(color: Colors.green, fontSize: 25.0),
),
uj5u.com熱心網友回復:
您應該將控制器直接分配給 TextField。
例如:
TextField(
controller: nota1Controller,//<-- HERE IT'S THE "CONTROLLER"
keyboardType: TextInputType.number,
decoration: InputDecoration(
labelText: "Nota 1",
labelStyle: TextStyle(color: Colors.green),
),
textAlign: TextAlign.center,
style: TextStyle(color: Colors.green, fontSize: 25.0),
),
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/530605.html
標籤:扑镖
