Skip to content

Commit 42aae80

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

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

lib/main.dart

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'dart:async';
22

3+
import 'package:dio/dio.dart';
34
import 'package:internet_connection_checker_plus/internet_connection_checker_plus.dart';
45
import 'package:firebase_core/firebase_core.dart';
56
import 'package:flutter/material.dart';
@@ -106,10 +107,25 @@ Future<void> main({String env = 'prod'}) async {
106107

107108
// Auto-sync when online
108109
final apiConnection = InternetConnection.createInstance(
110+
useDefaultOptions: false,
111+
enableStrictCheck: true,
109112
customCheckOptions: [
110-
// TODO: use /ping endpoint.
113+
// NOTE: this is dummy, all the logic is in customConnectivityCheck
111114
InternetCheckOption(uri: Uri.parse(apiClient.dio.options.baseUrl)),
112115
],
116+
customConnectivityCheck: (option) async {
117+
try {
118+
final pingApi = apiClient.getPingApi();
119+
final response = await pingApi.retrieve();
120+
121+
return InternetCheckResult(
122+
option: option,
123+
isSuccess: response.statusCode == 204,
124+
);
125+
} catch (_) {
126+
return InternetCheckResult(option: option, isSuccess: false);
127+
}
128+
},
113129
);
114130
apiConnection.onStatusChange.listen((status) async {
115131
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)