title: How to fix error Flutter Login via AWS Cognito
body: <p>I was writing code for user login on AWS using flutter and here is my code</p>
  
  <p>I was trying to create a login screen with AWS Cognito on flutter</p>
  
  <pre><code>Submit Method
   submit(BuildContext context) async {
      _formKey.currentState.save();
      String message;
      try {
        _user = await _userService.login(_user.email, _user.password);
        message = 'User sucessfully logged in!';
        if (!_user.confirmed) {
          message = 'Please confirm user account';
        }
      } on CognitoClientException catch (e) {
        if (e.code == 'InvalidParameterException' ||
            e.code == 'NotAuthorizedException' ||
            e.code == 'UserNotFoundException' ||
            e.code == 'ResourceNotFoundException') {
          message = e.message;
        } else {
          message = 'An unknown client error occured';
        }
      } catch (e) {
        message = 'An unknown error occurred';
      }
      final snackBar = new SnackBar(
        content: new Text(message),
        action: new SnackBarAction(
          label: 'OK',
          onPressed: () async {
            if (_user.hasAccess) {
              Navigator.pop(context);
              if (!_user.confirmed) {
                Navigator.push(
                  context,
                  new MaterialPageRoute(
                      builder: (context) =&gt;
                      new ConfirmationScreen(email: _user.email)),
                );
              }
            }
          },
        ),
        duration: new Duration(seconds: 30),
      );
  
      Scaffold.of(context).showSnackBar(snackBar);
    }
  
  </code></pre>
  
  <p>on Button Click, the submit method is being called</p>
  
  <pre><code>
                     Container(
                        height: 40.0,
                        child: Material(
                          borderRadius: BorderRadius.circular(20.0),
                          shadowColor: Colors.blueAccent,
                          color: Colors.blue,
                          elevation: 7.0,
                          child: GestureDetector(
                            onTap: () {
                                submit(context);
                            },
                            child: Center(
                              child: Text(
                                'LOGIN',
                                style: TextStyle(
                                    color: Colors.white,
                                    fontWeight: FontWeight.bold,
                                    fontFamily: 'Montserrat'),
                              ),
                            ),
                          ),
                        ),
                      ),
  </code></pre>
  
  <pre><code>This is the error that I'm seeing on the terminal when I click on the login button
  
  E/flutter (28368): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: NoSuchMethodError: The method 'save' was called on null.
  E/flutter (28368): Receiver: null
  E/flutter (28368): Tried calling: save()
  E/flutter (28368): #0      Object.noSuchMethod (dart:core-patch/object_patch.dart:50:5)
  E/flutter (28368): #1      _LoginScreenState.submit (package:flutter_ui_login/main.dart:69:27)
  E/flutter (28368): &lt;asynchronous suspension&gt;
  E/flutter (28368): #2      _LoginScreenState.build.&lt;anonymous closure&gt; (package:flutter_ui_login/main.dart:196:31)
  E/flutter (28368): #3      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:166:24)
  E/flutter (28368): #4      TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:240:9)
  E/flutter (28368): #5      TapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:177:9)
  E/flutter (28368): #6      PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:436:9)
  E/flutter (28368): #7      PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:73:12)
  E/flutter (28368): #8      PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:101:11)
  E/flutter (28368): #9      _WidgetsFlutterBinding&amp;BindingBase&amp;GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:221:19)
  E/flutter (28368): #10     _WidgetsFlutterBinding&amp;BindingBase&amp;GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:199:22)
  E/flutter (28368): #11     _WidgetsFlutterBinding&amp;BindingBase&amp;GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156:7)
  E/flutter (28368): #12     _WidgetsFlutterBinding&amp;BindingBase&amp;GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102:7)
  E/flutter (28368): #13     _WidgetsFlutterBinding&amp;BindingBase&amp;GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86:7)
  E/flutter (28368): #14     _rootRunUnary (dart:async/zone.dart:1136:13)
  E/flutter (28368): #15     _CustomZone.runUnary (dart:async/zone.dart:1029:19)
  E/flutter (28368): #16     _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7)
  E/flutter (28368): #17     _invoke1 (dart:ui/hooks.dart:233:10)
  E/flutter (28368): #18     _dispatchPointerDataPacket (dart:ui/hooks.dart:154:5)
  E/flutter (28368): 
  </code></pre>
  
  <p>I am not seeing any change on the app when I click on login and on the terminal I see the above messege.
  I was developing a small app for Cognito user login into AWS. If anyone of you has a different code for AWS Login, then please help me with that.</p>