Skip to content

Commit 905338d

Browse files
authored
Merge pull request Baseflow#37 from JeroenWeener/enhancement/platform-interface
Re-add platform interface
2 parents b4a0608 + 5580d3e commit 905338d

13 files changed

+453
-8
lines changed

CONTRIBUTING.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ We really appreciate contributions via GitHub pull requests. To contribute take
3333

3434
* Make sure you are up to date with the latest code on the master:
3535
* `git fetch upstream`
36-
* `git checkout upstream/develop -b <name_of_your_branch>`
36+
* `git checkout upstream/main -b <name_of_your_branch>`
3737
* Apply your changes
3838
* Verify your changes and fix potential warnings/ errors:
39-
* Check formatting: `flutter format .`
40-
* Run static analyses: `flutter analyzes`
39+
* Check formatting: `dart format .`
40+
* Run static analyses: `flutter analyze`
4141
* Run unit-tests: `flutter test`
4242
* Commit your changes: `git commit -am "<your informative commit message>"`
4343
* Push changes to your fork: `git push origin <name_of_your_branch>`
@@ -46,4 +46,4 @@ Send us your pull request:
4646

4747
* Go to `https://github.com/BaseflowIT/flutter-google-api-availability` and click the "Compare & pull request" button.
4848

49-
Please make sure you solved all warnings and errors reported by the static code analyses and that you fill in the full pull request template. Failing to do so will result in us asking you to fix it.
49+
Please make sure you solved all warnings and errors reported by the static code analyses and that you fill in the full pull request template. Failing to do so will result in us asking you to fix it.

google_api_availability/analysis_options.yaml renamed to analysis_options.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ analyzer:
77
- 'lib/src/generated/*.dart'
88
linter:
99
rules:
10-
- public_member_api_docs
10+
- public_member_api_docs
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: google_api_availability_example
22
description: Demonstrates how to use the google_api_availability plugin.
33
version: 1.0.0+1
4+
publish_to: none
45

56
environment:
67
sdk: ">=2.15.0 <3.0.0"
@@ -9,11 +10,11 @@ dependencies:
910
flutter:
1011
sdk: flutter
1112
cupertino_icons: ^0.1.2
12-
13-
dev_dependencies:
1413
google_api_availability:
1514
path: ../
15+
16+
dev_dependencies:
1617
flutter_lints: 1.0.4
1718

1819
flutter:
19-
uses-material-design: true
20+
uses-material-design: true
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 1.0.0
2+
3+
* Extracts the common platform interface from the google_api_availability package.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Baseflow
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# google_api_availability_platform_interface
2+
3+
[![style: flutter_lints](https://img.shields.io/badge/style-flutter_lints-40c4ff.svg)](https://pub.dev/packages/flutter_lints)
4+
5+
A common platform interface for the [`google_api_availability`][1] plugin.
6+
7+
This interface allows platform-specific implementations of the `google_api_availability`
8+
plugin, as well as the plugin itself, to ensure they are supporting the
9+
same interface. Have a look at the [Federated plugins](https://flutter.dev/docs/development/packages-and-plugins/developing-packages#federated-plugins)
10+
section of the official [Developing packages & plugins](https://flutter.dev/docs/development/packages-and-plugins/developing-packages)
11+
documentation for more information regarding the federated architecture concept.
12+
13+
## Usage
14+
15+
To implement a new platform-specific implementation of `google_api_availability`, extend
16+
[`GoogleApiAvailabilityPlatform`][2] with an implementation that performs the
17+
platform-specific behavior, and when you register your plugin, set the default
18+
`GoogleApiAvailabilityPlatform` by calling
19+
`GoogleApiAvailabilityPlatform.instance = MyGoogleApiAvailabilityPlatform()`.
20+
21+
## Note on breaking changes
22+
23+
Strongly prefer non-breaking changes (such as adding a method to the interface)
24+
over breaking changes for this package.
25+
26+
See https://flutter.dev/go/platform-interface-breaking-changes for a discussion
27+
on why a less-clean interface is preferable to a breaking change.
28+
29+
## Issues
30+
31+
Please file any issues, bugs or feature requests as an issue on our [GitHub](https://github.com/Baseflow/flutter-google-api-availability/issues) page. Commercial support is available, you can contact us at <[email protected]>.
32+
33+
## Want to contribute
34+
35+
If you would like to contribute to the plugin (e.g. by improving the documentation, solving a bug or adding a cool new feature), please carefully review our [contribution guide](../CONTRIBUTING.md) and send us your [pull request](https://github.com/Baseflow/flutter-google-api-availability/pulls).
36+
37+
## Author
38+
39+
This Google API Availability plugin for Flutter is developed by [Baseflow](https://baseflow.com).
40+
41+
[1]: ../google_api_availability
42+
[2]: lib/google_api_availability_platform_interface.dart
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
include: package:flutter_lints/flutter.yaml
2+
3+
analyzer:
4+
exclude:
5+
# Ignore generated files
6+
- '**/*.g.dart'
7+
- 'lib/src/generated/*.dart'
8+
linter:
9+
rules:
10+
- public_member_api_docs
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
library google_api_availability_platform_interface;
2+
3+
export 'src/google_api_availability_platform_interface.dart';
4+
export 'src/models/google_play_services_availability.dart';
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import 'package:meta/meta.dart';
2+
3+
/// Indicates possible states of the Google Api Services availability.
4+
class GooglePlayServicesAvailability {
5+
const GooglePlayServicesAvailability._(this.value);
6+
7+
/// Returns the value of the status as a string of the given status integer
8+
factory GooglePlayServicesAvailability.byValue(int value) => values[value];
9+
10+
/// Creates an instance of the [GooglePlayServicesAvailability] class. This
11+
/// constructor is exposed for testing purposes only and should not be used
12+
/// by clients of the plugin as it may break or change at any time.
13+
@visibleForTesting
14+
const GooglePlayServicesAvailability.private(this.value);
15+
16+
/// Represents the integer value of the Google Api Services availability
17+
/// state.
18+
final int value;
19+
20+
/// Google Play services are installed on the device and ready to be used.
21+
static const GooglePlayServicesAvailability success =
22+
GooglePlayServicesAvailability._(0);
23+
24+
/// Google Play services is missing on this device.
25+
static const GooglePlayServicesAvailability serviceMissing =
26+
GooglePlayServicesAvailability._(1);
27+
28+
/// Google Play service is currently being updated on this device.
29+
static const GooglePlayServicesAvailability serviceUpdating =
30+
GooglePlayServicesAvailability._(2);
31+
32+
/// The installed version of Google Play services is out of date.
33+
static const GooglePlayServicesAvailability serviceVersionUpdateRequired =
34+
GooglePlayServicesAvailability._(3);
35+
36+
/// The installed version of Google Play services has been disabled on this device.
37+
static const GooglePlayServicesAvailability serviceDisabled =
38+
GooglePlayServicesAvailability._(4);
39+
40+
/// The version of the Google Play services installed on this device is not authentic.
41+
static const GooglePlayServicesAvailability serviceInvalid =
42+
GooglePlayServicesAvailability._(5);
43+
44+
/// Google Play services are not available on this platform.
45+
static const GooglePlayServicesAvailability notAvailableOnPlatform =
46+
GooglePlayServicesAvailability._(6);
47+
48+
/// Unable to determine if Google Play services are installed.
49+
static const GooglePlayServicesAvailability unknown =
50+
GooglePlayServicesAvailability._(7);
51+
52+
/// Returns a list with all possible Google Api Availability states.
53+
static const List<GooglePlayServicesAvailability> values =
54+
<GooglePlayServicesAvailability>[
55+
success,
56+
serviceMissing,
57+
serviceUpdating,
58+
serviceVersionUpdateRequired,
59+
serviceDisabled,
60+
serviceInvalid,
61+
notAvailableOnPlatform,
62+
unknown,
63+
];
64+
65+
static const List<String> _names = <String>[
66+
'success',
67+
'serviceMissing',
68+
'serviceUpdating',
69+
'serviceVersionUpdateRequired',
70+
'serviceDisabled',
71+
'serviceInvalid',
72+
'notAvailableOnPlatform',
73+
'unknown',
74+
];
75+
76+
@override
77+
String toString() => 'GooglePlayServicesAvailability.${_names[value]}';
78+
}

0 commit comments

Comments
 (0)