I am trying running a code in Android Studio, but always I run the code, get this error:
Error: No named parameter with the name 'controller'.
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),
),
I navigate in a lot of sites, but I can't find a solution
CodePudding user response:
You are putting the controller inside the decoration, simply put it outside it:
change this:
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),
),
to this :
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),
),
CodePudding user response:
You should assign controller directly to the TextField.
Eg:
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),
),