title: Google Sign-In With Flutter: Error Code -4
body: <p>I currently try to implement google_sign_in package in Flutter (<a href="https://pub.dartlang.org/packages/google_sign_in" rel="noreferrer">https://pub.dartlang.org/packages/google_sign_in</a>).</p>
  
  <p>For this, I followed the example of their repository (<a href="https://github.com/flutter/plugins/blob/master/packages/google_sign_in/lib/google_sign_in.dart" rel="noreferrer">https://github.com/flutter/plugins/blob/master/packages/google_sign_in/lib/google_sign_in.dart</a>).</p>
  
  <p>In that example in "initState" is a call <em>signInSilently</em>.</p>
  
  <pre><code>@override
  void initState() {
    super.initState();
    _googleSignIn.onCurrentUserChanged.listen((GoogleSignInAccount account) {
      setState(() {
        _currentUser = account;
        loggedIn = true;
      });
    });
    loggedIn = false;
    _googleSignIn.signInSilently();
  }
  </code></pre>
  
  <p>I tried this code in iOS. On my first App Start, it worked well. But since I logged out I get an error here all the time I restart my app.It is the following PlatformException:</p>
  
  <pre><code>PlatformException(sign_in_required, com.google.GIDSignIn, The operation couldn’t be completed. (com.google.GIDSignIn error -4.))
  </code></pre>
  
  <p>I found in question <a href="https://stackoverflow.com/questions/37739557/google-sign-in-error-4">Google Sign-In Error -4</a> that the error code is because of a missing Auth in Keychain. </p>
  
  <p>The solution while swift programming is to call the method * hasAuthInKeychain* before the try to signInSilently. My problem is that the <em>GoogleSignIn</em> class in the flutter package has no function named like this.</p>
  
  <p>Is there another call I need to run with this package to be sure I can try a silent log in? Or am I doing something wrong to get this message or is there even the possibility of catching this error? </p>
  
  <h3>Edit</h3>
  
  <p>I tried Marcel's solution, too. Somehow it is not catching the PlatfromException. </p>
  
  <p>I do not know if this will help: signInSilently() is calling a method in which there is a the following call (google_sign_in.dart, line 217):</p>
  
  <pre><code>await channel.invokeMethod(method)
  </code></pre>
  
  <p>In platform_channel.dart there is a call </p>
  
  <pre><code>codec.decodeEnvelope(result);
  </code></pre>
  
  <p>The platform exception gets thrown in here.</p>
  
  <pre><code>if (errorCode is String &amp;&amp; (errorMessage == null || errorMessage is String) &amp;&amp; !buffer.hasRemaining)
    throw PlatformException(code: errorCode, message: errorMessage, details: errorDetails);
  else
    throw const FormatException('Invalid envelope');
  </code></pre>
  
  <h3>Edit 2</h3>
  
  <p>Since I just run my app and not started it in debug mode it somehow works again without throwing an exception. I do not know how this affects the code and why I got this exception. I can also run the code in debug mode again. </p>
  
  <p>Since then I had the exception once again. Again I restarted android studio and runned the application once without debug mode.</p>