@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
padding: const EdgeInsets.all(28),
color: Colors.blue.shade800,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.people, size: 78),
const TextField(
decoration: InputDecoration(label: Text("Login:")),
),
onChanged: _controller.setLogin,
const TextField(
decoration: InputDecoration(label: Text("Senha:")),
obscureText: true,
onChanged: _controller.setPass,
),
const SizedBox(
height: 25,
),
ElevatedButton(
onPressed: () {
_controller.auth();
},
child: const Text("Login"),
),
],
),
),
);
}
}
CodePudding user response:
Don't use const
when you're passing values and methods from controller.
It'll give you an error.
Also your onChanged
method is outside the TextField
.
Here's the workig code for you:
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
padding: const EdgeInsets.all(28),
color: Colors.blue.shade800,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.people, size: 78),
TextField(
decoration:const InputDecoration(label: Text("Login:")),
onChanged: _controller.setLogin,
),
TextField(
decoration: InputDecoration(label: Text("Senha:")),
obscureText: true,
onChanged: _controller.setPass,
),
const SizedBox(
height: 25,
),
ElevatedButton(
onPressed: () {
_controller.auth();
},
child: const Text("Login"),
),
],
),
),
);
}
CodePudding user response:
Try this:
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
padding: const EdgeInsets.all(28),
color: Colors.blue.shade800,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.people, size: 78),
const TextField(
decoration: InputDecoration(label: Text("Login:")),
onChanged: _controller.setLogin,
),
const TextField(
decoration: InputDecoration(label: Text("Senha:")),
obscureText: true,
onChanged: _controller.setPass,
),
const SizedBox(
height: 25,
),
ElevatedButton(
onPressed: () {
_controller.auth();
},
child: const Text("Login"),
),
],
),
),
);
}
CodePudding user response:
onChanged
should go inside TextField
and you will also need to remove const
from your TextField
. Here's the full working code:
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
padding: const EdgeInsets.all(28),
color: Colors.blue.shade800,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.people, size: 78),
TextField(
decoration: InputDecoration(label: Text("Login:")),
onChanged: _controller.setLogin,
),
TextField(
decoration: InputDecoration(label: Text("Senha:")),
obscureText: true,
onChanged: _controller.setPass,
),
const SizedBox(
height: 25,
),
ElevatedButton(
onPressed: () {
_controller.auth();
},
child: const Text("Login"),
),
],
),
),
);
}