Google sign in "Choose an account to continue" loop

826 Views Asked by At

I'm trying to implement the following packages with my Flutter app:

https://pub.dev/packages/permission_handler

https://pub.dev/packages/fit_kit

and I've done so by writing the following two functions:

Future<void> checkPermissions() async {
 var status = await Permission.activityRecognition.status;
 if (status.isUndetermined || status.isDenied) {
   Permission.activityRecognition.request();
}  else if (status.isPermanentlyDenied) {
   openAppSettings();
 }
}

Future<void> read() async {
 results.clear();
 await checkPermissions();
 for (DataType type in [DataType.STEP_COUNT, DataType.DISTANCE]) {
   try {
     results[type] = await FitKit.read(
       type,
       dateFrom: _weekBeginning,
       dateTo: _now,
     );
   } on UnsupportedException catch (e) {
     results[e.dataType] = [];
   }
 }
 dailyStepBuffer = 0;
 dailyDistanceBuffer = 0;
 for(FitData dataPoint in results[DataType.STEP_COUNT]){
   print(dataPoint);
   dailyStepBuffer += dataPoint.value.round();
 }
 for(FitData dataPoint in results[DataType.DISTANCE]){
   print(dataPoint);
   dailyDistanceBuffer += dataPoint.value.round();
 }
 setState(() {
   dailySteps = dailyStepBuffer;
   dailyDistance = dailyDistanceBuffer;
 });
}

The functions and packages work as intended on iOS, but for some reason, whenever I call read() on an Android device, it shows me this sign in screen, and when I click on my account, it does nothing and I get the error:

E/flutter ( 8211): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: PlatformException(FitKit, User denied permission access, null)

I've gotten the OAuth 2.0 client ID using my SHA-1 fingerprint, added <uses-permission android:name="android.permission.ACTIVITY_RECOGNITION"/> to my AndroidManifest.xml file and added the following to my build.gradle:

implementation 'com.google.android.gms:play-services-fitness:19.0.0'
implementation 'com.google.android.gms:play-services-auth:18.1.0'

Unfortunately though, none of these appear to have solved the issue. I'd be extremely grateful if anyone could help me solve this, thanks!

3

There are 3 best solutions below

0
On BEST ANSWER

It turned out that for some reason, my package name and application id were different, and so entering the application id instead of the package name when getting my OAuth 2.0 Client ID solved it.

1
On

It seems that the FitKit class has a requestPermissions method. Use that along with FitKit.hasPermissions to ensure that the necessary permissions are granted.

3
On

Can you try flutter clean and check if this persist?