Skip to content

Commit

Permalink
Fix(connectivity_provider.dart): Fixed API Change
Browse files Browse the repository at this point in the history
Changed type of ConnectivityResult to List (newly changed in ConnectivityPlus). Now receives list of results.
  • Loading branch information
thomaskim1130 committed Nov 7, 2024
1 parent c04bf5c commit 2e193e6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 22 deletions.
33 changes: 15 additions & 18 deletions lib/providers/connectivity_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,27 @@ class ConnectivityProvider with ChangeNotifier {

/// 'connectivitySubscription'값을 갱신하고 update에 listen하도록 합니다
void _initConnectivity() {
_connectSubscription = Connectivity()
.onConnectivityChanged
.listen((List<ConnectivityResult> results) {
for (ConnectivityResult result in results) {
showConnectivitySnackBar(result); //변화가 있을 시 snackBar 호출}
}
});
_connectSubscription = Connectivity().onConnectivityChanged.listen(
(List<ConnectivityResult> results) {
showConnectivitySnackBar(results); // 변화가 있을 시 snackBar 호출
},
);
}

/// 인터넷 연결 상태에 따라 [showInternetErrorBySnackBar]를 실행합니다.
void showConnectivitySnackBar(ConnectivityResult result) {
if (result == ConnectivityResult.none) {
//인터넷 연결 없음
void showConnectivitySnackBar(List<ConnectivityResult> result) {
if (result.contains(ConnectivityResult.wifi) ||
result.contains(ConnectivityResult.ethernet)) {
// 연결됨
_isConnected = true;
notifyListeners(); // 인터넷 복구를 알림
snackBarKey.currentState?.removeCurrentSnackBar();
debugPrint("Connected to ${result.last.toString().split('.').last}");
} else {
// 인터넷 연결 없음
_isConnected = false;

showInternetErrorBySnackBar(LocaleKeys.userProvider_internetError.tr());
debugPrint("Internet Connectivity Error");
} else {
//연결됨
_isConnected = true;
notifyListeners(); //인터넷 복구를 알림

snackBarKey.currentState?.clearSnackBars();
debugPrint("Connected to ${result.toString().split('.').last}");
}
}

Expand Down
16 changes: 12 additions & 4 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,18 @@ packages:
dependency: "direct main"
description:
name: connectivity_plus
sha256: "224a77051d52a11fbad53dd57827594d3bd24f945af28bd70bab376d68d437f0"
sha256: "876849631b0c7dc20f8b471a2a03142841b482438e3b707955464f5ffca3e4c3"
url: "https://pub.dev"
source: hosted
version: "5.0.2"
version: "6.1.0"
connectivity_plus_platform_interface:
dependency: transitive
description:
name: connectivity_plus_platform_interface
sha256: cf1d1c28f4416f8c654d7dc3cd638ec586076255d407cef3ddbdaf178272a71a
sha256: "42657c1715d48b167930d5f34d00222ac100475f73d10162ddf43e714932f204"
url: "https://pub.dev"
source: hosted
version: "1.2.4"
version: "2.0.1"
convert:
dependency: transitive
description:
Expand Down Expand Up @@ -166,6 +166,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "10.8.1"
dbus:
dependency: transitive
description:
name: dbus
sha256: "365c771ac3b0e58845f39ec6deebc76e3276aa9922b0cc60840712094d9047ac"
url: "https://pub.dev"
source: hosted
version: "0.7.10"
delta_to_html:
dependency: "direct main"
description:
Expand Down

0 comments on commit 2e193e6

Please sign in to comment.