Skip to content

Commit ea2dc99

Browse files
committed
Use ping endpoint for checking internet access
1 parent cbb13f3 commit ea2dc99

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

lib/main.dart

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,25 @@ Future<void> main({String env = 'prod'}) async {
106106

107107
// Auto-sync when online
108108
final apiConnection = InternetConnection.createInstance(
109+
useDefaultOptions: false,
110+
enableStrictCheck: true,
109111
customCheckOptions: [
110-
// TODO: use /ping endpoint.
112+
// NOTE: this is dummy, all the logic is in customConnectivityCheck
111113
InternetCheckOption(uri: Uri.parse(apiClient.dio.options.baseUrl)),
112114
],
115+
customConnectivityCheck: (option) async {
116+
try {
117+
final pingApi = apiClient.getPingApi();
118+
final response = await pingApi.retrieve();
119+
120+
return InternetCheckResult(
121+
option: option,
122+
isSuccess: response.statusCode == 204,
123+
);
124+
} catch (_) {
125+
return InternetCheckResult(option: option, isSuccess: false);
126+
}
127+
},
113128
);
114129
apiConnection.onStatusChange.listen((status) async {
115130
if (status == InternetStatus.connected) {

pubspec.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,11 +1176,11 @@ packages:
11761176
dependency: "direct main"
11771177
description:
11781178
path: "."
1179-
ref: "0.1.30"
1180-
resolved-ref: b45c55a48ae33d1017b11a2ded97c16076f9503c
1179+
ref: "0.1.31"
1180+
resolved-ref: ea50f7595e66d86b9eb82b0d7ab1e15dc8cc850a
11811181
url: "https://github.com/Mosquito-Alert/mosquito-alert-dart-sdk.git"
11821182
source: git
1183-
version: "0.1.30"
1183+
version: "0.1.31"
11841184
nested:
11851185
dependency: transitive
11861186
description:

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ dependencies:
5454
mosquito_alert:
5555
git:
5656
url: https://github.com/Mosquito-Alert/mosquito-alert-dart-sdk.git
57-
ref: 0.1.30
57+
ref: 0.1.31
5858
flutter_secure_storage: ^9.2.4
5959
infinite_scroll_pagination: ^5.1.0
6060
provider: ^6.1.5

0 commit comments

Comments
 (0)