Skip to content
This repository was archived by the owner on Jan 28, 2025. It is now read-only.

Commit 13a08da

Browse files
authoredOct 12, 2021
Merge pull request #1 from rajan-nonstopio/rajan/web
Rajan/web
2 parents 4702029 + b32f2d6 commit 13a08da

File tree

6 files changed

+132
-19
lines changed

6 files changed

+132
-19
lines changed
 

‎example/ios/Flutter/Debug.xcconfig

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
12
#include "Generated.xcconfig"

‎example/ios/Flutter/Release.xcconfig

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
12
#include "Generated.xcconfig"

‎example/pubspec.lock

+48-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,34 @@ packages:
4343
url: "https://pub.dartlang.org"
4444
source: hosted
4545
version: "1.15.0"
46+
connectivity:
47+
dependency: transitive
48+
description:
49+
name: connectivity
50+
url: "https://pub.dartlang.org"
51+
source: hosted
52+
version: "3.0.6"
53+
connectivity_for_web:
54+
dependency: transitive
55+
description:
56+
name: connectivity_for_web
57+
url: "https://pub.dartlang.org"
58+
source: hosted
59+
version: "0.4.0+1"
60+
connectivity_macos:
61+
dependency: transitive
62+
description:
63+
name: connectivity_macos
64+
url: "https://pub.dartlang.org"
65+
source: hosted
66+
version: "0.2.1+2"
67+
connectivity_platform_interface:
68+
dependency: transitive
69+
description:
70+
name: connectivity_platform_interface
71+
url: "https://pub.dartlang.org"
72+
source: hosted
73+
version: "2.0.1"
4674
connectivity_wrapper:
4775
dependency: "direct main"
4876
description:
@@ -74,6 +102,18 @@ packages:
74102
description: flutter
75103
source: sdk
76104
version: "0.0.0"
105+
flutter_web_plugins:
106+
dependency: transitive
107+
description: flutter
108+
source: sdk
109+
version: "0.0.0"
110+
js:
111+
dependency: transitive
112+
description:
113+
name: js
114+
url: "https://pub.dartlang.org"
115+
source: hosted
116+
version: "0.6.3"
77117
matcher:
78118
dependency: transitive
79119
description:
@@ -102,6 +142,13 @@ packages:
102142
url: "https://pub.dartlang.org"
103143
source: hosted
104144
version: "1.8.0"
145+
plugin_platform_interface:
146+
dependency: transitive
147+
description:
148+
name: plugin_platform_interface
149+
url: "https://pub.dartlang.org"
150+
source: hosted
151+
version: "2.0.2"
105152
provider:
106153
dependency: transitive
107154
description:
@@ -172,4 +219,4 @@ packages:
172219
version: "2.1.0"
173220
sdks:
174221
dart: ">=2.12.0 <3.0.0"
175-
flutter: ">=1.16.0"
222+
flutter: ">=1.20.0"

‎lib/connectivity_wrapper.dart

+32-17
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import 'dart:io';
1616

1717
// Project imports:
1818
import 'package:connectivity_wrapper/src/utils/constants.dart';
19+
import 'package:flutter/foundation.dart';
20+
import 'package:connectivity/connectivity.dart';
1921

2022
export 'package:connectivity_wrapper/src/widgets/connectivity_app_wrapper_widget.dart';
2123
export 'package:connectivity_wrapper/src/widgets/connectivity_screen_wrapper.dart';
@@ -29,23 +31,25 @@ export 'package:connectivity_wrapper/src/widgets/connectivity_widget_wrapper.dar
2931
enum ConnectivityStatus { CONNECTED, DISCONNECTED }
3032

3133
class ConnectivityWrapper {
32-
static final List<AddressCheckOptions> _defaultAddresses = List.unmodifiable([
33-
AddressCheckOptions(
34-
InternetAddress('1.1.1.1'),
35-
port: DEFAULT_PORT,
36-
timeout: DEFAULT_TIMEOUT,
37-
),
38-
AddressCheckOptions(
39-
InternetAddress('8.8.4.4'),
40-
port: DEFAULT_PORT,
41-
timeout: DEFAULT_TIMEOUT,
42-
),
43-
AddressCheckOptions(
44-
InternetAddress('208.67.222.222'),
45-
port: DEFAULT_PORT,
46-
timeout: DEFAULT_TIMEOUT,
47-
),
48-
]);
34+
static List<AddressCheckOptions> get _defaultAddresses => (kIsWeb)
35+
? []
36+
: List.unmodifiable([
37+
AddressCheckOptions(
38+
InternetAddress('1.1.1.1'),
39+
port: DEFAULT_PORT,
40+
timeout: DEFAULT_TIMEOUT,
41+
),
42+
AddressCheckOptions(
43+
InternetAddress('8.8.4.4'),
44+
port: DEFAULT_PORT,
45+
timeout: DEFAULT_TIMEOUT,
46+
),
47+
AddressCheckOptions(
48+
InternetAddress('208.67.222.222'),
49+
port: DEFAULT_PORT,
50+
timeout: DEFAULT_TIMEOUT,
51+
),
52+
]);
4953

5054
List<AddressCheckOptions> addresses = _defaultAddresses;
5155

@@ -83,6 +87,7 @@ class ConnectivityWrapper {
8387
List<AddressCheckResult> _lastTryResults = <AddressCheckResult>[];
8488

8589
Future<bool> get isConnected async {
90+
if (kIsWeb) return await _checkWebConnection();
8691
List<Future<AddressCheckResult>> requests = [];
8792

8893
for (var addressOptions in addresses) {
@@ -99,6 +104,16 @@ class ConnectivityWrapper {
99104
: ConnectivityStatus.DISCONNECTED;
100105
}
101106

107+
///
108+
Future<bool> _checkWebConnection() async {
109+
var connectivityResult = await (Connectivity().checkConnectivity());
110+
if (connectivityResult == ConnectivityResult.mobile ||
111+
connectivityResult == ConnectivityResult.wifi) {
112+
return true;
113+
}
114+
return false;
115+
}
116+
102117
Duration checkInterval = DEFAULT_INTERVAL;
103118

104119
_maybeEmitStatusUpdate([Timer? timer]) async {

‎pubspec.lock

+48-1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,34 @@ packages:
5050
url: "https://pub.dartlang.org"
5151
source: hosted
5252
version: "1.15.0"
53+
connectivity:
54+
dependency: "direct main"
55+
description:
56+
name: connectivity
57+
url: "https://pub.dartlang.org"
58+
source: hosted
59+
version: "3.0.6"
60+
connectivity_for_web:
61+
dependency: transitive
62+
description:
63+
name: connectivity_for_web
64+
url: "https://pub.dartlang.org"
65+
source: hosted
66+
version: "0.4.0+1"
67+
connectivity_macos:
68+
dependency: transitive
69+
description:
70+
name: connectivity_macos
71+
url: "https://pub.dartlang.org"
72+
source: hosted
73+
version: "0.2.1+2"
74+
connectivity_platform_interface:
75+
dependency: transitive
76+
description:
77+
name: connectivity_platform_interface
78+
url: "https://pub.dartlang.org"
79+
source: hosted
80+
version: "2.0.1"
5381
fake_async:
5482
dependency: transitive
5583
description:
@@ -67,13 +95,25 @@ packages:
6795
description: flutter
6896
source: sdk
6997
version: "0.0.0"
98+
flutter_web_plugins:
99+
dependency: transitive
100+
description: flutter
101+
source: sdk
102+
version: "0.0.0"
70103
import_sorter:
71104
dependency: "direct dev"
72105
description:
73106
name: import_sorter
74107
url: "https://pub.dartlang.org"
75108
source: hosted
76109
version: "4.5.0"
110+
js:
111+
dependency: transitive
112+
description:
113+
name: js
114+
url: "https://pub.dartlang.org"
115+
source: hosted
116+
version: "0.6.3"
77117
matcher:
78118
dependency: transitive
79119
description:
@@ -102,6 +142,13 @@ packages:
102142
url: "https://pub.dartlang.org"
103143
source: hosted
104144
version: "1.8.0"
145+
plugin_platform_interface:
146+
dependency: transitive
147+
description:
148+
name: plugin_platform_interface
149+
url: "https://pub.dartlang.org"
150+
source: hosted
151+
version: "2.0.2"
105152
provider:
106153
dependency: "direct main"
107154
description:
@@ -186,4 +233,4 @@ packages:
186233
version: "3.1.0"
187234
sdks:
188235
dart: ">=2.12.0 <3.0.0"
189-
flutter: ">=1.16.0"
236+
flutter: ">=1.20.0"

‎pubspec.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ dependencies:
1111
flutter:
1212
sdk: flutter
1313
provider: ^5.0.0
14+
connectivity: ^3.0.6 # To check connectivity for web only
15+
1416

1517
dev_dependencies:
1618
flutter_test:

0 commit comments

Comments
 (0)
This repository has been archived.