Sun Wareechuensuk
Sun Wareechuensuk

Reputation: 93

The getter 'text' was called on null

I am trying to get a user password from a pop up alertDialog. User type their password onto the textfield which has passController as a TextEditingController and the text is collected by calling passController.text, but and error occurred.

  void showDialog1(String msg, String jsonString) {

    TextEditingController passController;

    // flutter defined function
    showDialog(
      context: context,
      builder: (BuildContext context) {
        // return object of type Dialog
        return AlertDialog(
          title: new Text("Please Enter Password"),
          content: TextField(
              decoration: const InputDecoration(
                labelText: 'Password *',
              ),
              obscureText: true,
              controller: passController),
          actions: <Widget>[
            // usually buttons at the bottom of the dialog
            new FlatButton(
              child: new Text("OK"),
              onPressed: () {
                Navigator.of(context).pop();
                submit(jsonString, passController.text);
              },
            ),
          ],
        );
      },
    );
  }

This is the responded debug console.

I/flutter (12758): #6      TapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:275:7)
I/flutter (12758): #7      PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:455:9)
I/flutter (12758): #8      PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:75:13)
I/flutter (12758): #9      PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:102:11)
I/flutter (12758): #10     GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:218:19)
I/flutter (12758): #11     GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:198:22)
I/flutter (12758): #12     GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156:7)
I/flutter (12758): #13     GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102:7)
I/flutter (12758): #14     GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86:7)
I/flutter (12758): #18     _invoke1 (dart:ui/hooks.dart:263:10)
I/flutter (12758): #19     _dispatchPointerDataPacket (dart:ui/hooks.dart:172:5)
I/flutter (12758): (elided 3 frames from package dart:async)
I/flutter (12758):
I/flutter (12758): Handler: "onTap"
I/flutter (12758): Recognizer:
I/flutter (12758):   TapGestureRecognizer#f307f
I/flutter (12758): ════════════════════════════════════════════════════════════════════════════════════════════════════

Upvotes: 1

Views: 5492

Answers (1)

Snieder
Snieder

Reputation: 483

Since you are only creating the variable, it will always be null. Try this instead:

TextEditingController passController = new TextEditingController();

Upvotes: 11

Related Questions