I have a only one question
I begin learn a flutter in yesterday.
How to get a Textfield value ?
I tried call a TextEditingController anybody in a class. But It's not working to.
[![enter image description here][1]][1]
class LoginScreen extends StatefulWidget {
@override
_LoginState createState() => _LoginState();
}
class _LoginState extends State<LoginScreen> {
final userId = TextEditingController();
final userPass = TextEditingController();
...TextInputField(),
PasswordInput(),
LoginButton()
}
void loginAct() async {
var data = {
"user_id": userId, //undefined
"user_pass": userPass, //undefined
};
class TextInputField extends StatelessWidget {
const TextInputField({
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
return Padding(
padding: const EdgeInsets.symmetric(vertical: 10.0),
child: Container(
height: size.height * 0.08,
width: size.width * 0.8,
decoration: BoxDecoration(
color: Colors.grey[500],
borderRadius: BorderRadius.circular(16),
),
child: TextField(
controller: userId, <=== (The getter 'userId' isn't defined for the class 'TextInputField')
decoration: InputDecoration(
border: InputBorder.none,
prefixIcon: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20.0),
child: Icon(
FontAwesomeIcons.user,
size: 28,
color: Colors.black54,
),
),
hintText: 'id',
),
),
),
);
}
}
how to resolve that?