AndriousSolutions / auth

Other
47 stars 14 forks source link

Unable to sign in with Google #25

Closed hanskokx closed 3 years ago

hanskokx commented 3 years ago

auth: ^7.3.2 [√] Flutter (Channel stable, 1.22.6, on Microsoft Windows [Version 10.0.19042.804], locale en-US)

I'm unable to sign in with Google while using your example code. (To be fair,) I'm wedging it into my existing application.

The first thing I noticed was that this:

auth = Auth.init(
      scopes: [
        'email',
...

was telling me The method 'init' isn't defined for the type 'Auth', which I thought was strange. So, I removed .init, and moved on.

Next, I plopped your code into my sign-in page.

RaisedButton(
  onPressed: () {
    auth
        .signInWithGoogle()
        .then((signIn) => signInFunc(signIn: signIn))
        .catchError((Object err) {
      if (err is! Exception) {
        err = err.toString();
      }
      errorMessage = auth.message;
    });
  },
  child: const Text('Sign In With Google'),
),

The app compiles and runs, but when I tap the Sign In With Google button, I get the following error:

MissingPluginException(No implementation found for method init on channel plugins.flutter.io/google_sign_in)

I didn't have google_sign_in in my pubspec.yaml, so I added it thinking that might be the problem, but it hasn't helped.

Any suggestions?

hanskokx commented 3 years ago

More info:

environment:
  sdk: ">=2.7.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  async: ^2.4.2
  auth: ^7.3.2
  cloud_firestore: null
  firebase_core: ^0.7.0
  firebase_crashlytics: ^0.4.0+1
  flutter_dotenv: ^3.1.0
  google_sign_in: ^4.5.9
  modal_progress_hud: ^0.1.3
dev_dependencies:
  flutter_test:
    sdk: flutter
hanskokx commented 3 years ago

Repo: https://github.com/hanskokx/Punk-Messenger/tree/feature/login

Andrious commented 3 years ago

Just got in...reading your messages now.

Andrious commented 3 years ago

I'd recommend updating Dart to 2.10.0. That's the latest version in the Stable channel. Further, I'd just assign the major version number with trailing zeros: .0.0 to the dependencies. That'll keep your dependencies up-to-date with the latest minor updates and bug fixes.

pubspec.yaml file: ( The dependencies I feel I didn't need, I commented out. )

environment:
  sdk: ">=2.10.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  animated_text_kit: ^3.0.0
#  async: ^2.0.0
  auth: ^7.0.0
  cloud_firestore: ^0.16.0
  cupertino_icons: ^1.0.0
#  firebase_auth: ^0.20.0
#  firebase_core: ^0.7.0
  firebase_crashlytics: ^0.4.0
#  flutter_automation: ^1.0.0
  flutter_dotenv: ^3.0.0
#  flutter_svg: ^0.19.0
#  google_sign_in: ^4.0.0
  modal_progress_hud: ^0.1.0

Running under Android, I had to enable the Multi-Dex
\punk_messenger\android\app

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.punk_messenger"
        minSdkVersion 16
        targetSdkVersion 29
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName 
        multiDexEnabled true                                    <-----------  add this line.
    }

Finally, while in the directory where the pubspec.yaml file resides, delete the ios/ and android/ directories and run flutter create . to re-generate these directories.

hanskokx commented 3 years ago

The issue is resolved now. There were a few things that might have contributed.

https://github.com/hanskokx/Punk-Messenger/commit/2d4f78e433e643d706b6842c6cb9dced0d88eab9 https://github.com/hanskokx/Punk-Messenger/commit/1d6bf41e7e327d03f1bee0cfaf6b4cd0101868c5

Those are the commits with the changes I made. Now that I'm getting "proper" error messages from auth, I can at least confidently state that the problem doesn't appear to be related to the package. :)