v0.3.4simple_connection_checker
기기의 인터넷 연결 여부를 확인하는 간단한 패키지입니다. 또한 연결 상태 변경을 감시하는 메서드도 제공합니다.
ajomuch92/simple-connection-checker open-source repository details.
{"sdk":"flutter"}^1.3.0{"sdk":"flutter"}아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.
A simple package to check when the device is connected (connectivity) to internet. Also provide a method to listen for connection status changes.
Include simple_connection_checker in your pubspec.yaml file:
dependencies:
flutter:
sdk: flutter
simple_connection_checker: version
To use this package, just import it into your file and call the static method isConnectedToInternet as follows:
import 'package:simple_connection_checker/simple_connection_checker.dart';
...
bool isConnected = await SimpleConnectionChecker.isConnectedToInternet();
...
Note: You can pass an optional parameter named lookUpAddress to pass an especific URL to make the lookup operation and check the internet connection. By default, this value is www.google.com. Do not use the protocol on the URL string passed (http:// or https://).
import 'package:simple_connection_checker/simple_connection_checker.dart';
...
StreamSubscription? subscription;
bool? _connected;
@override
void initState() {
super.initState();
SimpleConnectionChecker _simpleConnectionChecker = SimpleConnectionChecker()
..setLookUpAddress('pub.dev'); //Optional method to pass the lookup string
subscription = _simpleConnectionChecker.onConnectionChange.listen((connected) {
setState(() {
_connected = connected;
});
});
}
@override
void dispose() {
subscription?.cancel();
super.dispose();
}
...
Note: Don't forget to cancel the subscription