Skip to content

Commit 7481abf

Browse files
committed
Updated dependency, added show error dialog
1 parent faffe13 commit 7481abf

File tree

5 files changed

+61
-1
lines changed

5 files changed

+61
-1
lines changed

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ android {
3939
}
4040

4141
dependencies {
42-
implementation 'com.google.android.gms:play-services-base:17.2.1'
42+
implementation 'com.google.android.gms:play-services-base:18.1.0'
4343
implementation 'androidx.annotation:annotation:1.1.0'
4444
}

android/src/main/java/com/baseflow/googleapiavailability/GoogleApiAvailabilityManager.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ interface showErrorNotificationCallback {
4040
void onSuccess(boolean showErrorNotificationCallback);
4141
}
4242

43+
@FunctionalInterface
44+
interface showErrorDialogFragmentCallback {
45+
void onSuccess(boolean showErrorDialogFragmentCallback);
46+
}
47+
4348
@FunctionalInterface
4449
interface ErrorCallback {
4550
void onError(String errorCode, String errorDescription);
@@ -121,4 +126,22 @@ void showErrorNotification(Context applicationContext, showErrorNotificationCall
121126

122127
successCallback.onSuccess(false);
123128
}
129+
130+
void showErrorDialogFragment(Context applicationContext, Activity activity, showErrorDialogFragmentCallback successCallback, ErrorCallback errorCallback) {
131+
if (applicationContext == null) {
132+
Log.d(GoogleApiAvailabilityConstants.LOG_TAG, "Context cannot be null.");
133+
errorCallback.onError("GoogleApiAvailability.showErrorDialogFragment", "Android context cannot be null.");
134+
return;
135+
}
136+
137+
final int errorCode = googleApiAvailability
138+
.isGooglePlayServicesAvailable(applicationContext);
139+
140+
if (errorCode != GoogleApiAvailabilityConstants.GOOGLE_PLAY_SERVICES_AVAILABILITY_SUCCESS) {
141+
googleApiAvailability.showErrorDialogFragment(activity, errorCode, GoogleApiAvailabilityConstants.REQUEST_GOOGLE_PLAY_SERVICES);
142+
successCallback.onSuccess(true);
143+
}
144+
145+
successCallback.onSuccess(false);
146+
}
124147
}

android/src/main/java/com/baseflow/googleapiavailability/MethodCallHandlerImpl.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
7878
null));
7979
break;
8080
}
81+
case "showErrorDialogFragment": {
82+
googleApiAvailabilityManager.showErrorDialogFragment(applicationContext, activity, result::success,(String errorCode, String errorDescription) -> result.error(
83+
errorCode,
84+
errorDescription,
85+
null));
86+
break;
87+
}
8188
default:
8289
result.notImplemented();
8390
break;

example/lib/main.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,15 @@ class _MyAppState extends State<MyApp> {
177177
Center(
178178
child: Text(
179179
'Error notification shown: $_errorNotificationShown\n')),
180+
MaterialButton(
181+
onPressed: () => showErrorDialogFragment(),
182+
child: const Text('Show error dialog fragment'),
183+
color: Colors.red,
184+
),
185+
Center(
186+
child: Text(
187+
'Error dialog shown: $_errorDialogShown\n')),
188+
180189
],
181190
)),
182191
);

lib/src/google_api_availability.dart

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,25 @@ class GoogleApiAvailability {
120120

121121
return showErrorNotification;
122122
}
123+
124+
/// Display an error dialog according to the [ErrorCode] if the connection status is not [SUCCESS].
125+
///
126+
/// Returns true if the connection status did not equal [SUCCESS] or
127+
/// any other non-[ConnectionResult] value.
128+
/// Returns false otherwise.
129+
Future<bool> showErrorDialogFragment() async {
130+
if (defaultTargetPlatform != TargetPlatform.android) {
131+
return false;
132+
}
133+
134+
final showErrorDialogFragment =
135+
await _methodChannel.invokeMethod('showErrorDialogFragment');
136+
137+
if (showErrorDialogFragment == null) {
138+
return false;
139+
}
140+
141+
return showErrorDialogFragment;
142+
}
143+
123144
}

0 commit comments

Comments
 (0)