Created
February 29, 2020 11:14
-
-
Save luizmarcus/22d773814bccd7fbedcefa5d78e9b974 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:connectivity/connectivity.dart'; | |
String _connection = ""; | |
final Connectivity _connectivity = Connectivity(); | |
StreamSubscription<ConnectivityResult> _connectivitySubscription; | |
@override | |
void initState() { | |
super.initState(); | |
_connectivitySubscription = | |
Connectivity().onConnectivityChanged.listen(_updateStatus); | |
} | |
void _updateStatus(ConnectivityResult connectivityResult) async{ | |
if (connectivityResult == ConnectivityResult.mobile) { | |
updateText("3G/4G"); | |
} else if (connectivityResult == ConnectivityResult.wifi) { | |
String wifiName = await _connectivity.getWifiName(); | |
String wifiSsid = await _connectivity.getWifiBSSID(); | |
String wifiIp = await _connectivity.getWifiIP(); | |
updateText("Wi-Fi\n$wifiName\n$wifiSsid\n$wifiIp"); | |
}else{ | |
updateText("Não Conectado!"); | |
} | |
} | |
void updateText(String texto){ | |
setState(() { | |
_connection = texto; | |
}); | |
} | |
@override | |
void dispose() { | |
_connectivitySubscription.cancel(); | |
super.dispose(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment