Retrieve Text Field Values in Flutter

Using TextEditingController

class LoginScreen extends StatefulWidget {
  _LoginScreenState createState() => _LoginScreenState();

class _LoginScreenState extends State<LoginScreen> {
  final _usernameController = TextEditingController();
  final _passwordController = TextEditingController();

  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        TextFormField(controller: _usernameController),
        TextFormField(controller: _passwordController, obscureText: true),
          onPressed: _performLogin,
          child: Text('Login'),

  void _performLogin() {
    String username = _usernameController.text;
    String password = _passwordController.text;

    // DO a HTTP POST request to trigger an actual login procedure

Subscribe to My Newsletter

The latest programming-related news, articles and resources - sent to your inbox monthly. Unsubscribe anytime.