From 63a2474bc4daceb9d04c5b3a11f17d29eb8d4954 Mon Sep 17 00:00:00 2001 From: Jeroen Weener Date: 2023年3月14日 10:23:34 +0100 Subject: [PATCH 01/10] Update PULL_REQUEST_TEMPLATE.md --- .github/PULL_REQUEST_TEMPLATE.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 65c98e2..7d4328a 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -19,6 +19,6 @@ ### :thinking: Checklist before submitting - [ ] All projects build -- [ ] Follows style guide lines ([code style guide](https://github.com/BaseflowIT/flutter-geolocator/blob/develop/CONTRIBUTING.md)) +- [ ] Follows style guide lines ([code style guide](https://github.com/BaseflowIT/flutter-google-api-availability/blob/main/CONTRIBUTING.md)) - [ ] Relevant documentation was updated -- [ ] Rebased onto current develop \ No newline at end of file +- [ ] Rebased onto current develop From f1c6aaf4c7969894e49602580c4f2c4fee2360e2 Mon Sep 17 00:00:00 2001 From: Jeroen Weener Date: 2023年3月14日 10:24:16 +0100 Subject: [PATCH 02/10] Remove android folder --- google_api_availability/android/.gitignore | 8 - google_api_availability/android/build.gradle | 44 ------ .../android/gradle.properties | 1 - .../gradle/wrapper/gradle-wrapper.properties | 5 - .../android/settings.gradle | 1 - .../android/src/main/AndroidManifest.xml | 3 - .../GoogleApiAvailabilityConstants.java | 59 ------- .../GoogleApiAvailabilityManager.java | 149 ------------------ .../GoogleApiAvailabilityPlugin.java | 82 ---------- .../MethodCallHandlerImpl.java | 93 ----------- 10 files changed, 445 deletions(-) delete mode 100644 google_api_availability/android/.gitignore delete mode 100644 google_api_availability/android/build.gradle delete mode 100644 google_api_availability/android/gradle.properties delete mode 100644 google_api_availability/android/gradle/wrapper/gradle-wrapper.properties delete mode 100644 google_api_availability/android/settings.gradle delete mode 100644 google_api_availability/android/src/main/AndroidManifest.xml delete mode 100644 google_api_availability/android/src/main/java/com/baseflow/googleapiavailability/GoogleApiAvailabilityConstants.java delete mode 100644 google_api_availability/android/src/main/java/com/baseflow/googleapiavailability/GoogleApiAvailabilityManager.java delete mode 100644 google_api_availability/android/src/main/java/com/baseflow/googleapiavailability/GoogleApiAvailabilityPlugin.java delete mode 100644 google_api_availability/android/src/main/java/com/baseflow/googleapiavailability/MethodCallHandlerImpl.java diff --git a/google_api_availability/android/.gitignore b/google_api_availability/android/.gitignore deleted file mode 100644 index c6cbe56..0000000 --- a/google_api_availability/android/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -*.iml -.gradle -/local.properties -/.idea/workspace.xml -/.idea/libraries -.DS_Store -/build -/captures diff --git a/google_api_availability/android/build.gradle b/google_api_availability/android/build.gradle deleted file mode 100644 index 125449a..0000000 --- a/google_api_availability/android/build.gradle +++ /dev/null @@ -1,44 +0,0 @@ -group 'com.baseflow.googleapiavailability' -version '1.0-SNAPSHOT' - -buildscript { - repositories { - google() - mavenCentral() - } - - dependencies { - classpath 'com.android.tools.build:gradle:4.1.0' - } -} - -rootProject.allprojects { - repositories { - google() - mavenCentral() - } -} - -apply plugin: 'com.android.library' - -android { - compileSdkVersion 31 - - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } - - defaultConfig { - minSdkVersion 16 - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - } - lintOptions { - disable 'InvalidPackage' - } -} - -dependencies { - implementation 'com.google.android.gms:play-services-base:18.1.0' - implementation 'androidx.annotation:annotation:1.1.0' -} \ No newline at end of file diff --git a/google_api_availability/android/gradle.properties b/google_api_availability/android/gradle.properties deleted file mode 100644 index 8bd86f6..0000000 --- a/google_api_availability/android/gradle.properties +++ /dev/null @@ -1 +0,0 @@ -org.gradle.jvmargs=-Xmx1536M diff --git a/google_api_availability/android/gradle/wrapper/gradle-wrapper.properties b/google_api_availability/android/gradle/wrapper/gradle-wrapper.properties deleted file mode 100644 index 69a9715..0000000 --- a/google_api_availability/android/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -1,5 +0,0 @@ -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists diff --git a/google_api_availability/android/settings.gradle b/google_api_availability/android/settings.gradle deleted file mode 100644 index f5ff5d0..0000000 --- a/google_api_availability/android/settings.gradle +++ /dev/null @@ -1 +0,0 @@ -rootProject.name = 'google_api_availability' diff --git a/google_api_availability/android/src/main/AndroidManifest.xml b/google_api_availability/android/src/main/AndroidManifest.xml deleted file mode 100644 index fd45006..0000000 --- a/google_api_availability/android/src/main/AndroidManifest.xml +++ /dev/null @@ -1,3 +0,0 @@ - - diff --git a/google_api_availability/android/src/main/java/com/baseflow/googleapiavailability/GoogleApiAvailabilityConstants.java b/google_api_availability/android/src/main/java/com/baseflow/googleapiavailability/GoogleApiAvailabilityConstants.java deleted file mode 100644 index 8c4aa2f..0000000 --- a/google_api_availability/android/src/main/java/com/baseflow/googleapiavailability/GoogleApiAvailabilityConstants.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.baseflow.googleapiavailability; - -import androidx.annotation.IntDef; - -import com.google.android.gms.common.ConnectionResult; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -final class GoogleApiAvailabilityConstants { - static final String LOG_TAG = "google_api_availability"; - - static final int REQUEST_GOOGLE_PLAY_SERVICES = 1000; - - //GOOGLE_PLAY_SERVICES_AVAILABILITY - static final int GOOGLE_PLAY_SERVICES_AVAILABILITY_SUCCESS = 0; - static final int GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_MISSING = 1; - static final int GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_UPDATING = 2; - static final int GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_VERSION_UPDATE_REQUIRED = 3; - static final int GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_DISABLED = 4; - static final int GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_INVALID = 5; - static final int GOOGLE_PLAY_SERVICES_AVAILABILITY_NOT_AVAILABLE_ON_PLATFORM = 6; - static final int GOOGLE_PLAY_SERVICES_AVAILABILITY_UNKNOWN = 7; - - - @Retention(RetentionPolicy.SOURCE) - @IntDef({ - GOOGLE_PLAY_SERVICES_AVAILABILITY_SUCCESS, - GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_MISSING, - GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_UPDATING, - GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_VERSION_UPDATE_REQUIRED, - GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_DISABLED, - GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_INVALID, - GOOGLE_PLAY_SERVICES_AVAILABILITY_NOT_AVAILABLE_ON_PLATFORM, - GOOGLE_PLAY_SERVICES_AVAILABILITY_UNKNOWN, - }) - @interface GooglePlayServicesAvailability { - } - - @GooglePlayServicesAvailability - static int toPlayServiceAvailability(int connectionResult) { - switch (connectionResult) { - case ConnectionResult.SUCCESS: - return GOOGLE_PLAY_SERVICES_AVAILABILITY_SUCCESS; - case ConnectionResult.SERVICE_MISSING: - return GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_MISSING; - case ConnectionResult.SERVICE_UPDATING: - return GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_UPDATING; - case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED: - return GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_VERSION_UPDATE_REQUIRED; - case ConnectionResult.SERVICE_DISABLED: - return GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_DISABLED; - case ConnectionResult.SERVICE_INVALID: - return GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_INVALID; - default: - return GOOGLE_PLAY_SERVICES_AVAILABILITY_UNKNOWN; - } - } -} diff --git a/google_api_availability/android/src/main/java/com/baseflow/googleapiavailability/GoogleApiAvailabilityManager.java b/google_api_availability/android/src/main/java/com/baseflow/googleapiavailability/GoogleApiAvailabilityManager.java deleted file mode 100644 index 8bb67ec..0000000 --- a/google_api_availability/android/src/main/java/com/baseflow/googleapiavailability/GoogleApiAvailabilityManager.java +++ /dev/null @@ -1,149 +0,0 @@ -package com.baseflow.googleapiavailability; - -import android.app.Activity; -import android.app.Dialog; -import android.app.PendingIntent; -import android.content.Context; -import android.util.Log; - -import com.google.android.gms.common.ConnectionResult; -import com.google.android.gms.common.GoogleApiAvailability; -import com.google.android.gms.tasks.Task; - -import java.util.List; - -public class GoogleApiAvailabilityManager { - - GoogleApiAvailability googleApiAvailability = GoogleApiAvailability.getInstance(); - - @FunctionalInterface - interface SuccessCallback { - void onSuccess(int connectionResult); - } - - @FunctionalInterface - interface MakeGooglePlayServicesAvailableCallback { - void onSuccess(Void v); - } - - @FunctionalInterface - interface getErrorStringCallback { - void onSuccess(String errorString); - } - - @FunctionalInterface - interface isUserResolvableCallback { - void onSuccess(boolean isUserResolvable); - } - - @FunctionalInterface - interface showErrorNotificationCallback { - void onSuccess(Void v); - } - - @FunctionalInterface - interface showErrorDialogFragmentCallback { - void onSuccess(boolean showErrorDialogFragmentCallback); - } - - @FunctionalInterface - interface ErrorCallback { - void onError(String errorCode, String errorDescription); - } - - void checkPlayServicesAvailability(Boolean showDialog, Activity activity, Context applicationContext, SuccessCallback successCallback, ErrorCallback errorCallback) { - if (applicationContext == null) { - Log.e(GoogleApiAvailabilityConstants.LOG_TAG, "The `ApplicationContext` cannot be null."); - errorCallback.onError("GoogleApiAvailability.GoogleApiAvailabilityManager", "Android `ApplicationContext` cannot be null."); - return; - } - - final int connectionResult = googleApiAvailability - .isGooglePlayServicesAvailable(applicationContext); - - if (activity == null) { - if (showDialog != null && showDialog) { - // Only log warning when `showDialog` property was `true`. - Log.w(GoogleApiAvailabilityConstants.LOG_TAG, "Unable to show dialog as `Activity` is not available."); - } - showDialog = false; - } - - if (showDialog != null && showDialog) { - googleApiAvailability - .showErrorDialogFragment(activity, connectionResult, GoogleApiAvailabilityConstants.REQUEST_GOOGLE_PLAY_SERVICES); - } - - successCallback.onSuccess(GoogleApiAvailabilityConstants.toPlayServiceAvailability(connectionResult)); - } - - void makeGooglePlayServicesAvailable(Activity activity, MakeGooglePlayServicesAvailableCallback successCallback, ErrorCallback errorCallback) { - if (activity == null) { - Log.e(GoogleApiAvailabilityConstants.LOG_TAG, "Activity cannot be null."); - errorCallback.onError("GoogleApiAvailability.makeGooglePlayServicesAvailable", "Android Activity cannot be null."); - return; - } - - googleApiAvailability.makeGooglePlayServicesAvailable(activity) - .addOnFailureListener((Exception e) -> errorCallback.onError("GoogleApiAvailability.makeGooglePlayServicesAvailable", e.getMessage())) - .addOnSuccessListener((Void t) -> successCallback.onSuccess(null)); - } - - void getErrorString(Context applicationContext, getErrorStringCallback successCallback, ErrorCallback errorCallback) { - if (applicationContext == null) { - Log.e(GoogleApiAvailabilityConstants.LOG_TAG, "Context cannot be null."); - errorCallback.onError("GoogleApiAvailability.getErrorString", "Android context cannot be null."); - return; - } - - final String errorString = googleApiAvailability.getErrorString(googleApiAvailability.isGooglePlayServicesAvailable(applicationContext)); - - successCallback.onSuccess(errorString); - } - - void isUserResolvable(Context applicationContext, isUserResolvableCallback successCallback, ErrorCallback errorCallback) { - if (applicationContext == null) { - Log.e(GoogleApiAvailabilityConstants.LOG_TAG, "Context cannot be null."); - errorCallback.onError("GoogleApiAvailability.isUserResolvable", "Android context cannot be null."); - return; - } - - final int connectionResult = googleApiAvailability - .isGooglePlayServicesAvailable(applicationContext); - - successCallback.onSuccess(googleApiAvailability.isUserResolvableError(connectionResult)); - } - - void showErrorNotification(Context applicationContext, showErrorNotificationCallback successCallback, ErrorCallback errorCallback) { - if (applicationContext == null) { - Log.e(GoogleApiAvailabilityConstants.LOG_TAG, "Context cannot be null."); - errorCallback.onError("GoogleApiAvailability.showErrorNotification", "Android context cannot be null."); - return; - } - - final int connectionResult = googleApiAvailability - .isGooglePlayServicesAvailable(applicationContext); - - googleApiAvailability.showErrorNotification(applicationContext, connectionResult); - - successCallback.onSuccess(null); - } - - void showErrorDialogFragment(Context applicationContext, Activity activity, showErrorDialogFragmentCallback successCallback, ErrorCallback errorCallback) { - if (applicationContext == null) { - Log.e(GoogleApiAvailabilityConstants.LOG_TAG, "Context cannot be null."); - errorCallback.onError("GoogleApiAvailability.showErrorDialogFragment", "Android context cannot be null."); - return; - } - - final int errorCode = googleApiAvailability - .isGooglePlayServicesAvailable(applicationContext); - - if (errorCode != GoogleApiAvailabilityConstants.GOOGLE_PLAY_SERVICES_AVAILABILITY_SUCCESS) { - googleApiAvailability.showErrorDialogFragment(activity, errorCode, GoogleApiAvailabilityConstants.REQUEST_GOOGLE_PLAY_SERVICES); - successCallback.onSuccess(true); - } - - successCallback.onSuccess(false); - } -} diff --git a/google_api_availability/android/src/main/java/com/baseflow/googleapiavailability/GoogleApiAvailabilityPlugin.java b/google_api_availability/android/src/main/java/com/baseflow/googleapiavailability/GoogleApiAvailabilityPlugin.java deleted file mode 100644 index 065b5c2..0000000 --- a/google_api_availability/android/src/main/java/com/baseflow/googleapiavailability/GoogleApiAvailabilityPlugin.java +++ /dev/null @@ -1,82 +0,0 @@ -package com.baseflow.googleapiavailability; - -import android.content.Context; -import androidx.annotation.NonNull; - -import io.flutter.embedding.engine.plugins.FlutterPlugin; -import io.flutter.embedding.engine.plugins.activity.ActivityAware; -import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding; -import io.flutter.plugin.common.BinaryMessenger; -import io.flutter.plugin.common.MethodChannel; -import io.flutter.plugin.common.PluginRegistry.Registrar; -import io.flutter.plugin.common.PluginRegistry.ViewDestroyListener; -import io.flutter.view.FlutterNativeView; - -/** - * GoogleApiAvailabilityPlugin - */ -public class GoogleApiAvailabilityPlugin implements FlutterPlugin, ActivityAware { - - private final GoogleApiAvailabilityManager googleApiAvailabilityManager; - private MethodChannel channel; - private MethodCallHandlerImpl methodCallHandler; - - public GoogleApiAvailabilityPlugin() { - this.googleApiAvailabilityManager = new GoogleApiAvailabilityManager(); - } - - @Override - public void onAttachedToActivity(ActivityPluginBinding binding) { - methodCallHandler.setActivity(binding.getActivity()); - } - - @Override - public void onDetachedFromActivity() { - methodCallHandler.setActivity(null); - } - - @Override - public void onReattachedToActivityForConfigChanges(@NonNull ActivityPluginBinding binding) { - methodCallHandler.setActivity(binding.getActivity()); - } - - @Override - public void onDetachedFromActivityForConfigChanges() { - methodCallHandler.setActivity(null); - } - - @Override - public void onAttachedToEngine(FlutterPluginBinding binding) { - registerPlugin(binding.getApplicationContext(), binding.getBinaryMessenger()); - } - - @Override - public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) { - unregisterPlugin(); - } - - public static void registerWith(Registrar registrar) { - final GoogleApiAvailabilityPlugin plugin = new GoogleApiAvailabilityPlugin(); - plugin.registerPlugin(registrar.context(), registrar.messenger()); - plugin.methodCallHandler.setActivity(registrar.activity()); - - registrar.addViewDestroyListener(new ViewDestroyListener() { - @Override - public boolean onViewDestroy(FlutterNativeView view) { - plugin.unregisterPlugin(); - return false; - } - }); - } - - private void registerPlugin(Context context, BinaryMessenger messenger) { - methodCallHandler = new MethodCallHandlerImpl(context, googleApiAvailabilityManager); - channel = new MethodChannel(messenger, "flutter.baseflow.com/google_api_availability/methods"); - channel.setMethodCallHandler(methodCallHandler); - } - - private void unregisterPlugin() { - channel.setMethodCallHandler(null); - channel = null; - } -} \ No newline at end of file diff --git a/google_api_availability/android/src/main/java/com/baseflow/googleapiavailability/MethodCallHandlerImpl.java b/google_api_availability/android/src/main/java/com/baseflow/googleapiavailability/MethodCallHandlerImpl.java deleted file mode 100644 index 4ce9ecc..0000000 --- a/google_api_availability/android/src/main/java/com/baseflow/googleapiavailability/MethodCallHandlerImpl.java +++ /dev/null @@ -1,93 +0,0 @@ -package com.baseflow.googleapiavailability; - -import android.app.Activity; -import android.content.Context; - -import androidx.annotation.IntDef; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - -import com.google.android.gms.common.ConnectionResult; -import com.google.android.gms.common.GoogleApiAvailability; - -import io.flutter.plugin.common.MethodCall; -import io.flutter.plugin.common.MethodChannel; -import io.flutter.plugin.common.MethodChannel.Result; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -public class MethodCallHandlerImpl implements MethodChannel.MethodCallHandler { - - private final GoogleApiAvailabilityManager googleApiAvailabilityManager; - - MethodCallHandlerImpl(Context applicationContext, GoogleApiAvailabilityManager googleApiAvailabilityManager) { - this.applicationContext = applicationContext; - - this.googleApiAvailabilityManager = googleApiAvailabilityManager; - } - - private final Context applicationContext; - - @Nullable - private Activity activity; - - void setActivity(@Nullable Activity activity) { - this.activity = activity; - } - - - @Override - public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) { - switch (call.method) { - case "checkPlayServicesAvailability": { - final Boolean showDialog = call.argument("showDialog"); - googleApiAvailabilityManager.checkPlayServicesAvailability(showDialog, activity, applicationContext, result::success, - (String errorCode, String errorDescription) -> result.error( - errorCode, - errorDescription, - null)); - break; - } - case "makeGooglePlayServicesAvailable": { - googleApiAvailabilityManager.makeGooglePlayServicesAvailable(activity,result::success, - (String errorCode, String errorDescription) -> result.error( - errorCode, - errorDescription, - null)); - break; - } - case "getErrorString": { - googleApiAvailabilityManager.getErrorString(applicationContext, result::success,(String errorCode, String errorDescription) -> result.error( - errorCode, - errorDescription, - null)); - break; - } - case "isUserResolvable": { - googleApiAvailabilityManager.isUserResolvable(applicationContext, result::success,(String errorCode, String errorDescription) -> result.error( - errorCode, - errorDescription, - null)); - break; - } - case "showErrorNotification": { - googleApiAvailabilityManager.showErrorNotification(applicationContext, result::success,(String errorCode, String errorDescription) -> result.error( - errorCode, - errorDescription, - null)); - break; - } - case "showErrorDialogFragment": { - googleApiAvailabilityManager.showErrorDialogFragment(applicationContext, activity, result::success,(String errorCode, String errorDescription) -> result.error( - errorCode, - errorDescription, - null)); - break; - } - default: - result.notImplemented(); - break; - } - } -} From 1f7a781ccb7589667aaa6b3d151b840a3b35442c Mon Sep 17 00:00:00 2001 From: Jeroen Weener Date: 2023年3月14日 10:25:45 +0100 Subject: [PATCH 03/10] Switch on PlatformInterface --- google_api_availability/CHANGELOG.md | 17 ++-- .../lib/google_api_availability.dart | 2 +- .../lib/src/google_api_availability.dart | 86 +++++++------------ .../google_play_services_availability.dart | 78 ----------------- google_api_availability/pubspec.yaml | 8 +- ...oogle_play_services_availability_test.dart | 29 ------- 6 files changed, 45 insertions(+), 175 deletions(-) delete mode 100644 google_api_availability/lib/src/models/google_play_services_availability.dart delete mode 100644 google_api_availability/test/google_play_services_availability_test.dart diff --git a/google_api_availability/CHANGELOG.md b/google_api_availability/CHANGELOG.md index a245503..1850867 100644 --- a/google_api_availability/CHANGELOG.md +++ b/google_api_availability/CHANGELOG.md @@ -1,11 +1,16 @@ +## 5.0.0 + +* **BREAKING CHANGES**: + * Uses the federated architecture. + ## 4.0.0 -* Changed the structure of the native code; -* Updated the example app; -* Added `makeGooglePlayServicesAvailable` ; -* Added `getErrorString`; -* Added `isUserResolvable`; -* Added `showErrorNotification`; +* Changed the structure of the native code. +* Updated the example app. +* Added `makeGooglePlayServicesAvailable`. +* Added `getErrorString`. +* Added `isUserResolvable`. +* Added `showErrorNotification`. * Added extra tests for the newly added methods. ## 3.0.2 diff --git a/google_api_availability/lib/google_api_availability.dart b/google_api_availability/lib/google_api_availability.dart index 86b4b42..c4eec26 100644 --- a/google_api_availability/lib/google_api_availability.dart +++ b/google_api_availability/lib/google_api_availability.dart @@ -1,4 +1,4 @@ library google_api_availability; export 'src/google_api_availability.dart'; -export 'src/models/google_play_services_availability.dart'; +export 'package:google_api_availability_platform_interface/google_api_availability_platform_interface.dart'; diff --git a/google_api_availability/lib/src/google_api_availability.dart b/google_api_availability/lib/src/google_api_availability.dart index 42a93f7..b0dd5c8 100644 --- a/google_api_availability/lib/src/google_api_availability.dart +++ b/google_api_availability/lib/src/google_api_availability.dart @@ -1,73 +1,55 @@ import 'dart:async'; import 'package:flutter/foundation.dart'; -import 'package:flutter/services.dart'; +import 'package:google_api_availability_platform_interface/google_api_availability_platform_interface.dart'; -import '../google_api_availability.dart'; - -/// Flutter plugin to verify if Google Play Services are installed on the -/// device. +/// Flutter plugin to verify if Google Play Services are installed on the device. class GoogleApiAvailability { const GoogleApiAvailability._(); - /// Creates an instance of the [GoogleApiAvailability] class. This - /// constructor is exposed for testing purposes only and should not be used - /// by clients of the plugin as it may break or change at any time. + /// Creates an instance of the [GoogleApiAvailability] class. + /// + /// This constructor is exposed for testing purposes only and should not be + /// used by clients of the plugin as it may break or change at any time. @visibleForTesting const GoogleApiAvailability.private(); /// Acquires an instance of the [GoogleApiAvailability] class. static const GoogleApiAvailability instance = GoogleApiAvailability._(); - static const MethodChannel _methodChannel = - MethodChannel('flutter.baseflow.com/google_api_availability/methods'); - - /// This feature is only available on Android devices. On any other platforms - /// the [checkPlayServicesAvailability] method will always return - /// [GooglePlayServicesAvailability.notAvailableOnPlatform]. - /// /// Returns the connection status of Google Play Service. - /// Optionally, you can also show an error dialog if the connection status is not [SUCCESS]. + /// + /// Optionally, you can also show an error dialog if the connection status is + /// not [SUCCESS]. Future checkGooglePlayServicesAvailability( [bool showDialogIfNecessary = false]) async { - if (defaultTargetPlatform != TargetPlatform.android) { - throw UnsupportedError('Not available on non Android devices.'); - } - - final availability = await _methodChannel.invokeMethod( - 'checkPlayServicesAvailability', - {'showDialog': showDialogIfNecessary}); + final availability = await GoogleApiAvailabilityPlatform.instance + ?.checkGooglePlayServicesAvailability(showDialogIfNecessary); if (availability == null) { return GooglePlayServicesAvailability.unknown; } - return GooglePlayServicesAvailability.values[availability]; + return GooglePlayServicesAvailability.values[availability.value]; } - /// Attempts to make Google Play services available on this device. + /// Attempts to make Google Play Services available on this device. + /// /// Shows a dialog if the error is resolvable by user. /// - /// If the `Future` completes without throwing an exception, Play Services - /// is available on this device. + /// If the `Future` completes without throwing an exception, Play Services is + /// available on this device. Future makeGooglePlayServicesAvailable() async { - if (defaultTargetPlatform != TargetPlatform.android) { - throw UnsupportedError('Not available on non Android devices.'); - } - - await _methodChannel.invokeMethod('makeGooglePlayServicesAvailable'); + await GoogleApiAvailabilityPlatform.instance + ?.makeGooglePlayServicesAvailable(); } /// Returns a human-readable string of the error code. - /// Will return "Not available on non Android devices" if used on iOS. Future getErrorString() async { - if (defaultTargetPlatform != TargetPlatform.android) { - throw UnsupportedError('Not available on non Android devices.'); - } - - final errorString = await _methodChannel.invokeMethod('getErrorString'); + final errorString = + await GoogleApiAvailabilityPlatform.instance?.getErrorString(); if (errorString == null) { - return "ErrorString is null"; + return 'ErrorString is null'; } return errorString; @@ -75,12 +57,8 @@ class GoogleApiAvailability { /// Determines whether an error can be resolved via user action. Future isUserResolvable() async { - if (defaultTargetPlatform != TargetPlatform.android) { - throw UnsupportedError('Not available on non Android devices.'); - } - final isUserResolvable = - await _methodChannel.invokeMethod('isUserResolvable'); + await GoogleApiAvailabilityPlatform.instance?.isUserResolvable(); if (isUserResolvable == null) { return false; @@ -90,28 +68,22 @@ class GoogleApiAvailability { } /// Displays a notification for an error code, if it is resolvable by the user. + /// /// This method is similar to [showErrorDialogFragment], but is provided for /// background tasks that cannot or should not display dialogs. Future showErrorNotification() async { - if (defaultTargetPlatform != TargetPlatform.android) { - throw UnsupportedError('Not available on non Android devices.'); - } - - await _methodChannel.invokeMethod('showErrorNotification'); + await GoogleApiAvailabilityPlatform.instance?.showErrorNotification(); } - /// Display an error dialog according to the [ErrorCode] if the connection status is not [SUCCESS]. + /// Display an error dialog according to the [ErrorCode] if the connection + /// status is not [SUCCESS]. /// - /// Returns true if the connection status did not equal [SUCCESS] or - /// any other non-[ConnectionResult] value. + /// Returns true if the connection status did not equal [SUCCESS] or any other + /// non-[ConnectionResult] value. /// Returns false otherwise. Future showErrorDialogFragment() async { - if (defaultTargetPlatform != TargetPlatform.android) { - throw UnsupportedError('Not available on non Android devices.'); - } - final showErrorDialogFragment = - await _methodChannel.invokeMethod('showErrorDialogFragment'); + await GoogleApiAvailabilityPlatform.instance?.showErrorDialogFragment(); if (showErrorDialogFragment == null) { return false; diff --git a/google_api_availability/lib/src/models/google_play_services_availability.dart b/google_api_availability/lib/src/models/google_play_services_availability.dart deleted file mode 100644 index ec2f506..0000000 --- a/google_api_availability/lib/src/models/google_play_services_availability.dart +++ /dev/null @@ -1,78 +0,0 @@ -import 'package:meta/meta.dart'; - -/// Indicates possible states of the Google Api Services availability. -class GooglePlayServicesAvailability { - const GooglePlayServicesAvailability._(this.value); - - /// Returns the value of the status as a string of the given status integer - factory GooglePlayServicesAvailability.byValue(int value) => values[value]; - - /// Creates an instance of the [GoogleApiAvailability] class. This - /// constructor is exposed for testing purposes only and should not be used - /// by clients of the plugin as it may break or change at any time. - @visibleForTesting - const GooglePlayServicesAvailability.private(this.value); - - /// Represents the integer value of the Google Api Services availability - /// state. - final int value; - - /// Google Play services are installed on the device and ready to be used. - static const GooglePlayServicesAvailability success = - GooglePlayServicesAvailability._(0); - - /// Google Play services is missing on this device. - static const GooglePlayServicesAvailability serviceMissing = - GooglePlayServicesAvailability._(1); - - /// Google Play service is currently being updated on this device. - static const GooglePlayServicesAvailability serviceUpdating = - GooglePlayServicesAvailability._(2); - - /// The installed version of Google Play services is out of date. - static const GooglePlayServicesAvailability serviceVersionUpdateRequired = - GooglePlayServicesAvailability._(3); - - /// The installed version of Google Play services has been disabled on this device. - static const GooglePlayServicesAvailability serviceDisabled = - GooglePlayServicesAvailability._(4); - - /// The version of the Google Play services installed on this device is not authentic. - static const GooglePlayServicesAvailability serviceInvalid = - GooglePlayServicesAvailability._(5); - - /// Google Play services are not available on this platform. - static const GooglePlayServicesAvailability notAvailableOnPlatform = - GooglePlayServicesAvailability._(6); - - /// Unable to determine if Google Play services are installed. - static const GooglePlayServicesAvailability unknown = - GooglePlayServicesAvailability._(7); - - /// Returns a list with all possible Google Api Availability states. - static const List values = - [ - success, - serviceMissing, - serviceUpdating, - serviceVersionUpdateRequired, - serviceDisabled, - serviceInvalid, - notAvailableOnPlatform, - unknown, - ]; - - static const List _names = [ - 'success', - 'serviceMissing', - 'serviceUpdating', - 'serviceVersionUpdateRequired', - 'serviceDisabled', - 'serviceInvalid', - 'notAvailableOnPlatform', - 'unknown', - ]; - - @override - String toString() => 'GooglePlayServicesAvailability.${_names[value]}'; -} diff --git a/google_api_availability/pubspec.yaml b/google_api_availability/pubspec.yaml index 538e36b..8187074 100644 --- a/google_api_availability/pubspec.yaml +++ b/google_api_availability/pubspec.yaml @@ -1,6 +1,6 @@ name: google_api_availability description: A Flutter plugin to check the availability of Google Play Services on an Android device. -version: 4.0.0 +version: 5.0.0 homepage: https://github.com/baseflowit/flutter-google-api-availability environment: @@ -10,7 +10,8 @@ environment: dependencies: flutter: sdk: flutter - meta: ^1.8.0 + google_api_availability_android: ^1.0.0+1 + google_api_availability_platform_interface: ^1.0.0 dev_dependencies: flutter_test: @@ -21,5 +22,4 @@ flutter: plugin: platforms: android: - package: com.baseflow.googleapiavailability - pluginClass: GoogleApiAvailabilityPlugin + default_package: google_api_availability_android diff --git a/google_api_availability/test/google_play_services_availability_test.dart b/google_api_availability/test/google_play_services_availability_test.dart deleted file mode 100644 index 3abf1cd..0000000 --- a/google_api_availability/test/google_play_services_availability_test.dart +++ /dev/null @@ -1,29 +0,0 @@ -import 'package:flutter_test/flutter_test.dart'; -import 'package:google_api_availability/google_api_availability.dart'; - -void main() { - test( - 'GooglePlayServicesAvailability has the right amount of availability states', - () { - const values = GooglePlayServicesAvailability.values; - - expect(values.length, 8); - }); - - test('check if corresponding status gets received when calling constructor', - () { - const values = GooglePlayServicesAvailability.values; - - for (var i = 0; i < values.length; i++) { - expect(values[i], GooglePlayServicesAvailability.byValue(i)); - } - }); - - test('check if toString method returns the corresponding name', () { - var playServicesAvailability = - const GooglePlayServicesAvailability.private(0); - - expect(playServicesAvailability.toString(), - 'GooglePlayServicesAvailability.success'); - }); -} From 3e37253659030bdb96e6cb6861db9bbfe92b0a80 Mon Sep 17 00:00:00 2001 From: Jeroen Weener Date: 2023年3月14日 10:25:52 +0100 Subject: [PATCH 04/10] Update example --- .../example/ios/Flutter/AppFrameworkInfo.plist | 2 +- google_api_availability/example/ios/Podfile | 2 +- .../example/ios/Runner.xcodeproj/project.pbxproj | 12 +++++++----- .../xcshareddata/xcschemes/Runner.xcscheme | 2 +- .../example/ios/Runner/Info.plist | 4 ++++ google_api_availability/example/lib/main.dart | 10 +++++----- google_api_availability/example/pubspec.yaml | 1 - 7 files changed, 19 insertions(+), 14 deletions(-) diff --git a/google_api_availability/example/ios/Flutter/AppFrameworkInfo.plist b/google_api_availability/example/ios/Flutter/AppFrameworkInfo.plist index 9367d48..9625e10 100644 --- a/google_api_availability/example/ios/Flutter/AppFrameworkInfo.plist +++ b/google_api_availability/example/ios/Flutter/AppFrameworkInfo.plist @@ -21,6 +21,6 @@ CFBundleVersion 1.0 MinimumOSVersion - 8.0 + 11.0 diff --git a/google_api_availability/example/ios/Podfile b/google_api_availability/example/ios/Podfile index f7d6a5e..d207307 100644 --- a/google_api_availability/example/ios/Podfile +++ b/google_api_availability/example/ios/Podfile @@ -1,5 +1,5 @@ # Uncomment this line to define a global platform for your project -# platform :ios, '9.0' +# platform :ios, '11.0' # CocoaPods analytics sends network stats synchronously affecting flutter build latency. ENV['COCOAPODS_DISABLE_STATS'] = 'true' diff --git a/google_api_availability/example/ios/Runner.xcodeproj/project.pbxproj b/google_api_availability/example/ios/Runner.xcodeproj/project.pbxproj index a1093af..d3d10ec 100644 --- a/google_api_availability/example/ios/Runner.xcodeproj/project.pbxproj +++ b/google_api_availability/example/ios/Runner.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 46; + objectVersion = 54; objects = { /* Begin PBXBuildFile section */ @@ -166,7 +166,7 @@ 97C146E61CF9000F007C117D /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0910; + LastUpgradeCheck = 1300; ORGANIZATIONNAME = "The Chromium Authors"; TargetAttributes = { 97C146ED1CF9000F007C117D = { @@ -210,6 +210,7 @@ /* Begin PBXShellScriptBuildPhase section */ 3B06AD1E1E4923F5004D2608 /* Thin Binary */ = { isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; buildActionMask = 2147483647; files = ( ); @@ -246,6 +247,7 @@ }; 9740EEB61CF901F6004384FC /* Run Script */ = { isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; buildActionMask = 2147483647; files = ( ); @@ -332,7 +334,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; @@ -409,7 +411,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -456,7 +458,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; diff --git a/google_api_availability/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/google_api_availability/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index 786d6aa..f156018 100644 --- a/google_api_availability/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/google_api_availability/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -1,6 +1,6 @@ UIViewControllerBasedStatusBarAppearance + CADisableMinimumFrameDurationOnPhone +
+ UIApplicationSupportsIndirectInputEvents +
diff --git a/google_api_availability/example/lib/main.dart b/google_api_availability/example/lib/main.dart index e799169..5803e03 100644 --- a/google_api_availability/example/lib/main.dart +++ b/google_api_availability/example/lib/main.dart @@ -6,9 +6,9 @@ import 'package:google_api_availability/google_api_availability.dart'; void main() => runApp(const MyApp()); -///Creates the mutable state for this widget +///Creates the mutable state for this widget. class MyApp extends StatefulWidget { - ///Named [key] parameter to identify a widget + /// Named [key] parameter to identify a widget. const MyApp({Key? key}) : super(key: key); @override @@ -18,7 +18,7 @@ class MyApp extends StatefulWidget { class _MyAppState extends State { GooglePlayServicesAvailability _playStoreAvailability = GooglePlayServicesAvailability.unknown; - String _errorString = "unknown"; + String _errorString = 'unknown'; bool _isUserResolvable = false; bool _errorDialogFragmentShown = false; @@ -63,7 +63,7 @@ class _MyAppState extends State { try { errorString = await GoogleApiAvailability.instance.getErrorString(); } on PlatformException { - errorString = "Not available on non Android devices"; + errorString = 'Not available on non Android devices'; } if (!mounted) { @@ -153,7 +153,7 @@ class _MyAppState extends State { 'Google Play Store status: ${_playStoreAvailability.toString().split('.').last}\n')), MaterialButton( onPressed: () => makeGooglePlayServicesAvailable(), - child: const Text('Make Google Play Service availabe'), + child: const Text('Make Google Play Service available'), color: Colors.red, ), const SizedBox(height: 30), diff --git a/google_api_availability/example/pubspec.yaml b/google_api_availability/example/pubspec.yaml index 7a444bf..f78738d 100644 --- a/google_api_availability/example/pubspec.yaml +++ b/google_api_availability/example/pubspec.yaml @@ -9,7 +9,6 @@ environment: dependencies: flutter: sdk: flutter - cupertino_icons: ^0.1.2 google_api_availability: path: ../ From 565c75848320fac60a11fed75b92b7130cd265d1 Mon Sep 17 00:00:00 2001 From: Jeroen Weener Date: 2023年3月14日 10:27:12 +0100 Subject: [PATCH 05/10] Update CHANGELOG.md --- google_api_availability/CHANGELOG.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/google_api_availability/CHANGELOG.md b/google_api_availability/CHANGELOG.md index 1850867..98c1ca9 100644 --- a/google_api_availability/CHANGELOG.md +++ b/google_api_availability/CHANGELOG.md @@ -1,7 +1,6 @@ ## 5.0.0 -* **BREAKING CHANGES**: - * Uses the federated architecture. +* **BREAKING CHANGE**: Uses the federated architecture. ## 4.0.0 From 5a6d26075be71e0cd0feb1c4d0975d75424c5505 Mon Sep 17 00:00:00 2001 From: Jeroen Weener Date: 2023年3月14日 11:38:42 +0100 Subject: [PATCH 06/10] Updates tests --- .../lib/src/google_api_availability.dart | 55 +-- google_api_availability/pubspec.yaml | 2 + .../test/google_api_availability_test.dart | 378 +++++++++--------- .../test/method_channel_mock.dart | 34 -- 4 files changed, 226 insertions(+), 243 deletions(-) delete mode 100644 google_api_availability/test/method_channel_mock.dart diff --git a/google_api_availability/lib/src/google_api_availability.dart b/google_api_availability/lib/src/google_api_availability.dart index b0dd5c8..a9baf8d 100644 --- a/google_api_availability/lib/src/google_api_availability.dart +++ b/google_api_availability/lib/src/google_api_availability.dart @@ -16,19 +16,19 @@ class GoogleApiAvailability { /// Acquires an instance of the [GoogleApiAvailability] class. static const GoogleApiAvailability instance = GoogleApiAvailability._(); - /// Returns the connection status of Google Play Service. + /// Returns the connection status of Google Play Services. /// /// Optionally, you can also show an error dialog if the connection status is /// not [SUCCESS]. Future checkGooglePlayServicesAvailability( [bool showDialogIfNecessary = false]) async { - final availability = await GoogleApiAvailabilityPlatform.instance - ?.checkGooglePlayServicesAvailability(showDialogIfNecessary); - - if (availability == null) { - return GooglePlayServicesAvailability.unknown; + if (GoogleApiAvailabilityPlatform.instance == null) { + throw UnsupportedError('This platform is not supported.'); } + final availability = await GoogleApiAvailabilityPlatform.instance! + .checkGooglePlayServicesAvailability(showDialogIfNecessary); + return GooglePlayServicesAvailability.values[availability.value]; } @@ -39,31 +39,34 @@ class GoogleApiAvailability { /// If the `Future` completes without throwing an exception, Play Services is /// available on this device. Future makeGooglePlayServicesAvailable() async { - await GoogleApiAvailabilityPlatform.instance - ?.makeGooglePlayServicesAvailable(); + if (GoogleApiAvailabilityPlatform.instance == null) { + throw UnsupportedError('This platform is not supported.'); + } + await GoogleApiAvailabilityPlatform.instance! + .makeGooglePlayServicesAvailable(); } /// Returns a human-readable string of the error code. Future getErrorString() async { - final errorString = - await GoogleApiAvailabilityPlatform.instance?.getErrorString(); - - if (errorString == null) { - return 'ErrorString is null'; + if (GoogleApiAvailabilityPlatform.instance == null) { + throw UnsupportedError('This platform is not supported.'); } + final errorString = + await GoogleApiAvailabilityPlatform.instance!.getErrorString(); + return errorString; } /// Determines whether an error can be resolved via user action. Future isUserResolvable() async { - final isUserResolvable = - await GoogleApiAvailabilityPlatform.instance?.isUserResolvable(); - - if (isUserResolvable == null) { - return false; + if (GoogleApiAvailabilityPlatform.instance == null) { + throw UnsupportedError('This platform is not supported.'); } + final isUserResolvable = + await GoogleApiAvailabilityPlatform.instance!.isUserResolvable(); + return isUserResolvable; } @@ -72,7 +75,11 @@ class GoogleApiAvailability { /// This method is similar to [showErrorDialogFragment], but is provided for /// background tasks that cannot or should not display dialogs. Future showErrorNotification() async { - await GoogleApiAvailabilityPlatform.instance?.showErrorNotification(); + if (GoogleApiAvailabilityPlatform.instance == null) { + throw UnsupportedError('This platform is not supported.'); + } + + await GoogleApiAvailabilityPlatform.instance!.showErrorNotification(); } /// Display an error dialog according to the [ErrorCode] if the connection @@ -82,13 +89,13 @@ class GoogleApiAvailability { /// non-[ConnectionResult] value. /// Returns false otherwise. Future showErrorDialogFragment() async { - final showErrorDialogFragment = - await GoogleApiAvailabilityPlatform.instance?.showErrorDialogFragment(); - - if (showErrorDialogFragment == null) { - return false; + if (GoogleApiAvailabilityPlatform.instance == null) { + throw UnsupportedError('This platform is not supported.'); } + final showErrorDialogFragment = + await GoogleApiAvailabilityPlatform.instance!.showErrorDialogFragment(); + return showErrorDialogFragment; } } diff --git a/google_api_availability/pubspec.yaml b/google_api_availability/pubspec.yaml index 8187074..1d7f662 100644 --- a/google_api_availability/pubspec.yaml +++ b/google_api_availability/pubspec.yaml @@ -17,6 +17,8 @@ dev_dependencies: flutter_test: sdk: flutter flutter_lints: 1.0.4 + mocktail: ^0.3.0 + plugin_platform_interface: ^2.1.4 flutter: plugin: diff --git a/google_api_availability/test/google_api_availability_test.dart b/google_api_availability/test/google_api_availability_test.dart index f6267d3..1a5e553 100644 --- a/google_api_availability/test/google_api_availability_test.dart +++ b/google_api_availability/test/google_api_availability_test.dart @@ -1,208 +1,216 @@ -import 'package:flutter/foundation.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:google_api_availability/google_api_availability.dart'; +import 'package:plugin_platform_interface/plugin_platform_interface.dart'; +import 'package:mocktail/mocktail.dart'; -import 'method_channel_mock.dart'; +class MockGoogleApiAvailabilityPlatform extends Mock + with MockPlatformInterfaceMixin + implements GoogleApiAvailabilityPlatform {} void main() { TestWidgetsFlutterBinding.ensureInitialized(); - group('checkGooglePlayServiceAvailability', () { - test('Should throw UnsuppertedError if not Android', () async { - debugDefaultTargetPlatformOverride = TargetPlatform.iOS; + group('GoogleApiAvailability', () { + late GoogleApiAvailabilityPlatform googleApiAvailabilityPlatform; + late GoogleApiAvailability googleApiAvailability; - expect( - () async => await const GoogleApiAvailability.private() - .checkGooglePlayServicesAvailability(), - throwsA(isA())); - - debugDefaultTargetPlatformOverride = null; + setUp(() { + // Arrange. + googleApiAvailabilityPlatform = MockGoogleApiAvailabilityPlatform(); + GoogleApiAvailabilityPlatform.instance = googleApiAvailabilityPlatform; + googleApiAvailability = const GoogleApiAvailability.private(); }); - test('Should receive the corresponding GooglePlayServiceAvailability', - () async { - const availability = GooglePlayServicesAvailability.serviceDisabled; - - MethodChannelMock( - channelName: 'flutter.baseflow.com/google_api_availability/methods', - method: 'checkPlayServicesAvailability', - result: availability.value, - ); - - final googlePlayServiceAvailability = - await const GoogleApiAvailability.private() - .checkGooglePlayServicesAvailability(); - - expect(googlePlayServiceAvailability, availability); - }); - - test( - 'Should receive GooglePlayServiceAvailability.unknown when availability is null', - () async { - const availability = null; - - MethodChannelMock( - channelName: 'flutter.baseflow.com/google_api_availability/methods', - method: 'checkPlayServicesAvailability', - result: availability, - ); - - final googlePlayServiceAvailability = - await const GoogleApiAvailability.private() - .checkGooglePlayServicesAvailability(); - - expect(googlePlayServiceAvailability, - GooglePlayServicesAvailability.unknown); - }); - }); - - group('makeGooglePlayServicesAvailable', () { - test('Should throw UnsuppertedError if not Android', () async { - debugDefaultTargetPlatformOverride = TargetPlatform.iOS; - - expect( - () async => await const GoogleApiAvailability.private() - .makeGooglePlayServicesAvailable(), - throwsA(isA())); - - debugDefaultTargetPlatformOverride = null; + group('checkGooglePlayServicesAvailability', () { + test('Should throw if no platform implementation is registered', + () async { + // Arrange. + GoogleApiAvailabilityPlatform.removeInstance(); + + // Act & Assert. + expect( + googleApiAvailability.checkGooglePlayServicesAvailability, + throwsA(isA()), + ); + }); + + test('Should receive the corresponding $GooglePlayServicesAvailability', + () async { + // Arrange. + const availability = GooglePlayServicesAvailability.serviceDisabled; + + when(() => googleApiAvailabilityPlatform + .checkGooglePlayServicesAvailability()) + .thenAnswer((_) async => availability); + + // Act. + final googlePlayServiceAvailability = + await googleApiAvailability.checkGooglePlayServicesAvailability(); + + // Assert. + expect( + googlePlayServiceAvailability, + availability, + ); + }); }); - }); - - group('getErrorString', () { - test('Should throw UnsuppertedError if not on Android', () async { - debugDefaultTargetPlatformOverride = TargetPlatform.iOS; - - expect( - () async => - await const GoogleApiAvailability.private().getErrorString(), - throwsA(isA())); - debugDefaultTargetPlatformOverride = null; + group('makeGooglePlayServicesAvailable', () { + test('Should throw if no platform implementation is registered', + () async { + // Arrange. + GoogleApiAvailabilityPlatform.removeInstance(); + + // Act & Assert. + expect( + googleApiAvailability.makeGooglePlayServicesAvailable, + throwsA(isA()), + ); + }); }); - test('Should receive "ErrorString is null" when availability is null', - () async { - const errorString = null; - - MethodChannelMock( - channelName: 'flutter.baseflow.com/google_api_availability/methods', - method: 'getErrorString', - result: errorString, - ); - - final errorStringResult = - await const GoogleApiAvailability.private().getErrorString(); - - expect(errorStringResult, "ErrorString is null"); + group('getErrorString', () { + test('Should throw if no platform implementation is registered', + () async { + // Arrange. + GoogleApiAvailabilityPlatform.removeInstance(); + + // Act & Assert. + expect( + googleApiAvailability.getErrorString, + throwsA(isA()), + ); + }); + + test('Should receive the corresponding error string', () async { + // Arrange. + const expectedErrorString = 'test_error_string'; + + when(() => googleApiAvailabilityPlatform.getErrorString()) + .thenAnswer((_) async => expectedErrorString); + + // Act. + final errorString = + await const GoogleApiAvailability.private().getErrorString(); + + // Assert. + expect( + errorString, + expectedErrorString, + ); + }); }); - test('Should receive SUCCESS when connection status is success', () async { - MethodChannelMock( - channelName: 'flutter.baseflow.com/google_api_availability/methods', - method: 'getErrorString', - result: "SUCCESS", - ); - - final errorString = - await const GoogleApiAvailability.private().getErrorString(); - - expect(errorString, "SUCCESS"); + group('isUserResolvable', () { + test('Should throw if no platform implementation is registered', + () async { + // Arrange. + GoogleApiAvailabilityPlatform.removeInstance(); + + // Act & Assert. + expect( + googleApiAvailability.isUserResolvable, + throwsA(isA()), + ); + }); + + test('Should receive true if the user is resolvable', () async { + // Arrange. + const expectedIsUserResolvable = true; + + when(() => googleApiAvailabilityPlatform.isUserResolvable()) + .thenAnswer((_) async => expectedIsUserResolvable); + + // Act. + final isUserResolvable = await googleApiAvailability.isUserResolvable(); + + // Assert. + expect( + isUserResolvable, + expectedIsUserResolvable, + ); + }); + + test('Should receive false if the user is not resolvable', () async { + // Arrange. + const expectedIsUserResolvable = false; + + when(() => googleApiAvailabilityPlatform.isUserResolvable()) + .thenAnswer((_) async => expectedIsUserResolvable); + + // Act. + final isUserResolvable = await googleApiAvailability.isUserResolvable(); + + // Assert. + expect( + isUserResolvable, + expectedIsUserResolvable, + ); + }); }); - }); - group('isUserResolvable', () { - test('Should throw UnsuppertedError if not Android', () async { - debugDefaultTargetPlatformOverride = TargetPlatform.iOS; - - expect( - () async => - await const GoogleApiAvailability.private().isUserResolvable(), - throwsA(isA())); - - debugDefaultTargetPlatformOverride = null; + group('showErrorNotification', () { + test('Should throw if no platform implementation is registered', + () async { + // Arrange. + GoogleApiAvailabilityPlatform.removeInstance(); + + // Act & Assert. + expect( + googleApiAvailability.showErrorNotification, + throwsA(isA()), + ); + }); }); - test('Should receive false when isUserResolvable is null', () async { - const isUserResolvable = null; - - MethodChannelMock( - channelName: 'flutter.baseflow.com/google_api_availability/methods', - method: 'isUserResolvable', - result: isUserResolvable, - ); - - final isUserResolvableResult = - await const GoogleApiAvailability.private().isUserResolvable(); - - expect(isUserResolvableResult, false); - }); - - test('Should receive true when error is user resolvable', () async { - MethodChannelMock( - channelName: 'flutter.baseflow.com/google_api_availability/methods', - method: 'isUserResolvable', - result: true, - ); - - final isUserResolvable = - await const GoogleApiAvailability.private().isUserResolvable(); - - expect(isUserResolvable, true); - }); - }); - - group('showErrorNotification', () { - test('Should throw UnsuppertedError if not Android', () async { - debugDefaultTargetPlatformOverride = TargetPlatform.iOS; - - expect( - () async => await const GoogleApiAvailability.private() - .showErrorNotification(), - throwsA(isA())); - - debugDefaultTargetPlatformOverride = null; - }); - }); - - group('showErrorDialogFragment', () { - test('Should throw UnsuppertedError if not Android', () async { - debugDefaultTargetPlatformOverride = TargetPlatform.iOS; - - expect( - () async => await const GoogleApiAvailability.private() - .showErrorDialogFragment(), - throwsA(isA())); - - debugDefaultTargetPlatformOverride = null; - }); - - test('Should receive false when showErrorDialogFragment is null', () async { - const showErrorDialogFragment = null; - - MethodChannelMock( - channelName: 'flutter.baseflow.com/google_api_availability/methods', - method: 'showErrorDialogFragment', - result: showErrorDialogFragment, - ); - - final showErrorDialogFragmentResult = - await const GoogleApiAvailability.private().showErrorDialogFragment(); - - expect(showErrorDialogFragmentResult, false); - }); - - test('Should receive true when error dialog fragment is shown', () async { - MethodChannelMock( - channelName: 'flutter.baseflow.com/google_api_availability/methods', - method: 'showErrorDialogFragment', - result: true, - ); - - final showErrorDialogFragment = - await const GoogleApiAvailability.private().showErrorDialogFragment(); - - expect(showErrorDialogFragment, true); + group('showErrorDialogFragment', () { + test('Should throw if no platform implementation is registered', + () async { + // Arrange. + GoogleApiAvailabilityPlatform.removeInstance(); + + // Act & Assert. + expect( + googleApiAvailability.showErrorDialogFragment, + throwsA(isA()), + ); + }); + + test('Should receive false when dialog should not be shown', () async { + // Arrange. + const expectedShowDialogFragment = false; + + when(() => googleApiAvailabilityPlatform.showErrorDialogFragment()) + .thenAnswer((_) async => expectedShowDialogFragment); + + // Act. + final showErrorDialogFragment = + await googleApiAvailability.showErrorDialogFragment(); + + // Assert. + expect( + expectedShowDialogFragment, + showErrorDialogFragment, + ); + }); + + test('Should receive true when dialog should be shown', () async { + // Arrange. + const expectedShowDialogFragment = true; + + when(() => googleApiAvailabilityPlatform.showErrorDialogFragment()) + .thenAnswer((_) async => expectedShowDialogFragment); + + // Act. + final showErrorDialogFragment = + await googleApiAvailability.showErrorDialogFragment(); + + // Assert. + expect( + expectedShowDialogFragment, + showErrorDialogFragment, + ); + }); }); }); } diff --git a/google_api_availability/test/method_channel_mock.dart b/google_api_availability/test/method_channel_mock.dart deleted file mode 100644 index ad85720..0000000 --- a/google_api_availability/test/method_channel_mock.dart +++ /dev/null @@ -1,34 +0,0 @@ -import 'package:flutter/services.dart'; -import 'package:flutter_test/flutter_test.dart'; - -class MethodChannelMock { - final MethodChannel methodChannel; - final String method; - final dynamic result; - final Duration delay; - - MethodChannelMock({ - required String channelName, - required this.method, - this.result, - this.delay = Duration.zero, - }) : methodChannel = MethodChannel(channelName) { - TestDefaultBinaryMessengerBinding.instance!.defaultBinaryMessenger - .setMockMethodCallHandler(methodChannel, _handler); - } - - Future _handler(MethodCall methodCall) async { - if (methodCall.method != method) { - throw MissingPluginException('No implementation found for method ' - '$method on channel ${methodChannel.name}'); - } - - return Future.delayed(delay, () { - if (result is Exception) { - throw result; - } - - return Future.value(result); - }); - } -} From c3f403468dc7f05650d984ccdd49f4f4ff774d65 Mon Sep 17 00:00:00 2001 From: Jeroen Weener Date: 2023年3月14日 12:47:21 +0100 Subject: [PATCH 07/10] Update CHANGELOG.md --- google_api_availability/CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/google_api_availability/CHANGELOG.md b/google_api_availability/CHANGELOG.md index 98c1ca9..f252623 100644 --- a/google_api_availability/CHANGELOG.md +++ b/google_api_availability/CHANGELOG.md @@ -1,6 +1,7 @@ ## 5.0.0 -* **BREAKING CHANGE**: Uses the federated architecture. +* **BREAKING CHANGE**: No longer supports iOS, as it was never truly supported. +* Uses the federated architecture. ## 4.0.0 From 63bd9a2dd975c8d67e1873466702dff62a85c495 Mon Sep 17 00:00:00 2001 From: Jeroen Weener Date: 2023年3月14日 12:50:38 +0100 Subject: [PATCH 08/10] Update google_api_availability.dart --- google_api_availability/lib/google_api_availability.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google_api_availability/lib/google_api_availability.dart b/google_api_availability/lib/google_api_availability.dart index c4eec26..90ec98e 100644 --- a/google_api_availability/lib/google_api_availability.dart +++ b/google_api_availability/lib/google_api_availability.dart @@ -1,4 +1,4 @@ library google_api_availability; export 'src/google_api_availability.dart'; -export 'package:google_api_availability_platform_interface/google_api_availability_platform_interface.dart'; +export 'package:google_api_availability_platform_interface/src/models/google_play_services_availability.dart'; From 43ddaa63e1694bbe3a6ff5bde00370cf21a3f478 Mon Sep 17 00:00:00 2001 From: Jeroen Weener Date: 2023年3月14日 12:57:57 +0100 Subject: [PATCH 09/10] Add missing import --- google_api_availability/test/google_api_availability_test.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/google_api_availability/test/google_api_availability_test.dart b/google_api_availability/test/google_api_availability_test.dart index 1a5e553..70b642d 100644 --- a/google_api_availability/test/google_api_availability_test.dart +++ b/google_api_availability/test/google_api_availability_test.dart @@ -1,5 +1,6 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:google_api_availability/google_api_availability.dart'; +import 'package:google_api_availability_platform_interface/google_api_availability_platform_interface.dart'; import 'package:plugin_platform_interface/plugin_platform_interface.dart'; import 'package:mocktail/mocktail.dart'; From 8848f15ef868838735675aa0b6b960ab3f0bd9a5 Mon Sep 17 00:00:00 2001 From: Jeroen Weener Date: 2023年3月23日 16:40:05 +0100 Subject: [PATCH 10/10] Update pubspec and changelog --- google_api_availability/CHANGELOG.md | 2 +- google_api_availability/pubspec.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/google_api_availability/CHANGELOG.md b/google_api_availability/CHANGELOG.md index f252623..6682a51 100644 --- a/google_api_availability/CHANGELOG.md +++ b/google_api_availability/CHANGELOG.md @@ -1,6 +1,6 @@ ## 5.0.0 -* **BREAKING CHANGE**: No longer supports iOS, as it was never truly supported. +* **BREAKING CHANGE**: Removes support for iOS, as it was never truly supported. * Uses the federated architecture. ## 4.0.0 diff --git a/google_api_availability/pubspec.yaml b/google_api_availability/pubspec.yaml index 1d7f662..38f6b30 100644 --- a/google_api_availability/pubspec.yaml +++ b/google_api_availability/pubspec.yaml @@ -11,7 +11,7 @@ dependencies: flutter: sdk: flutter google_api_availability_android: ^1.0.0+1 - google_api_availability_platform_interface: ^1.0.0 + google_api_availability_platform_interface: ^1.0.1 dev_dependencies: flutter_test:

AltStyle によって変換されたページ (->オリジナル) /