|
| 1 | +import 'package:google_api_availability_platform_interface/google_api_availability_platform_interface.dart'; |
| 2 | +import 'package:plugin_platform_interface/plugin_platform_interface.dart'; |
| 3 | + |
| 4 | +/// The interface that implementations of `google_api_availability` must implement. |
| 5 | +/// |
| 6 | +/// Platform implementations should extend this class rather than implement it |
| 7 | +/// as `google_api_availability` does not consider newly added methods to be |
| 8 | +/// breaking changes. Extending this class (using `extends`) ensures that the |
| 9 | +/// subclass will get the default implementation, while platform implementations |
| 10 | +/// that `implements` this interface will be broken by newly added |
| 11 | +/// [GoogleApiAvailabilityPlatform] methods. |
| 12 | +abstract class GoogleApiAvailabilityPlatform extends PlatformInterface { |
| 13 | + /// Constructs a [GoogleApiAvailabilityPlatform]. |
| 14 | + GoogleApiAvailabilityPlatform() : super(token: _token); |
| 15 | + |
| 16 | + static final Object _token = Object(); |
| 17 | + |
| 18 | + static GoogleApiAvailabilityPlatform? _instance; |
| 19 | + |
| 20 | + /// The default instance of [GoogleApiAvailabilityPlatform] to use. |
| 21 | + static GoogleApiAvailabilityPlatform? get instance => _instance; |
| 22 | + |
| 23 | + /// Platform-specific plugins should set this with their own platform-specific |
| 24 | + /// class that extends [GoogleApiAvailabilityPlatform] when they register |
| 25 | + /// themselves. |
| 26 | + static set instance(GoogleApiAvailabilityPlatform? instance) { |
| 27 | + if (instance == null) { |
| 28 | + throw AssertionError( |
| 29 | + 'Platform interfaces can only be set to a non-null instance'); |
| 30 | + } |
| 31 | + |
| 32 | + PlatformInterface.verify(instance, _token); |
| 33 | + _instance = instance; |
| 34 | + } |
| 35 | + |
| 36 | + /// Returns the connection status of Google Play Service. |
| 37 | + /// |
| 38 | + /// Optionally, you can also show an error dialog if the connection status is |
| 39 | + /// not [GooglePlayServicesAvailability.success]. |
| 40 | + Future<GooglePlayServicesAvailability> checkGooglePlayServicesAvailability([ |
| 41 | + bool showDialogIfNecessary = false, |
| 42 | + ]) { |
| 43 | + throw UnimplementedError( |
| 44 | + 'checkGooglePlayServicesAvailability() has not been implemented.', |
| 45 | + ); |
| 46 | + } |
| 47 | + |
| 48 | + /// Attempts to make Google Play Services available on this device. |
| 49 | + /// |
| 50 | + /// Shows a dialog if the error is resolvable by user. |
| 51 | + /// If the `Future` completes without throwing an exception, Play Services |
| 52 | + /// is available on this device. |
| 53 | + Future<void> makeGooglePlayServicesAvailable() { |
| 54 | + throw UnimplementedError( |
| 55 | + 'makeGooglePlayServicesAvailable() has not been implemented.', |
| 56 | + ); |
| 57 | + } |
| 58 | + |
| 59 | + /// Returns a human-readable string of the error code. |
| 60 | + Future<String> getErrorString() { |
| 61 | + throw UnimplementedError( |
| 62 | + 'getErrorString() has not been implemented.', |
| 63 | + ); |
| 64 | + } |
| 65 | + |
| 66 | + /// Determines whether an error can be resolved via user action. |
| 67 | + Future<bool> isUserResolvable() { |
| 68 | + throw UnimplementedError( |
| 69 | + 'isUserResolvable() has not been implemented.', |
| 70 | + ); |
| 71 | + } |
| 72 | + |
| 73 | + /// Displays a notification for an error code, if it is resolvable by the user. |
| 74 | + /// |
| 75 | + /// This method is similar to [showErrorDialogFragment], but is provided for |
| 76 | + /// background tasks that cannot or should not display dialogs. |
| 77 | + Future<void> showErrorNotification() { |
| 78 | + throw UnimplementedError( |
| 79 | + 'showErrorNotification() has not been implemented.', |
| 80 | + ); |
| 81 | + } |
| 82 | + |
| 83 | + /// Display an error dialog according to the [ErrorCode] if the connection |
| 84 | + /// status is not [GooglePlayServicesAvailability.success]. |
| 85 | + /// |
| 86 | + /// Returns true if the connection status did not equal |
| 87 | + /// [GooglePlayServicesAvailability.success] or any other |
| 88 | + /// non-[ConnectionResult] value. |
| 89 | + /// Returns false otherwise. |
| 90 | + Future<bool> showErrorDialogFragment() { |
| 91 | + throw UnimplementedError( |
| 92 | + 'showErrorDialogFragment() has not been implemented.', |
| 93 | + ); |
| 94 | + } |
| 95 | +} |
0 commit comments