Created
March 25, 2019 13:46
-
-
Save bmatheus91/1d426bc33cfdd938735e51ca255a5e22 to your computer and use it in GitHub Desktop.
Uso da lib connectivity para pegar o IP na rede WIFI do aparelho.
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'; | |
import 'dart:async'; | |
import 'package:flutter/services.dart'; | |
ConnectivityResult result; | |
String wifiName, wifiIP; | |
// Primeiro e necessario verificar a conectividade do aparelho | |
try { | |
result = await _connectivity.checkConnectivity(); | |
} on PlatformException catch (e) { | |
print(e.toString()); | |
} | |
// Executa a logica dependendo do tipo de conexao que o aparelho tem | |
if (result == ConnectivityResult.mobile) { | |
// I am connected to a mobile network. | |
print('to no mobile'); | |
} else if (result == ConnectivityResult.wifi) { | |
// I am connected to a wifi network. | |
// Pega o nome da rede WIFI | |
try { | |
wifiName = (await _connectivity.getWifiName()).toString(); | |
} on PlatformException catch (e) { | |
print(e.toString()); | |
wifiName = "Failed to get Wifi Name"; | |
} | |
// Pega o IP do aparelho na rede | |
try { | |
wifiIP = (await _connectivity.getWifiIP()).toString(); | |
} on PlatformException catch (e) { | |
print(e.toString()); | |
wifiName = "Failed to get Wifi IP"; | |
} | |
} | |
print(wifiName); | |
print(wifiIP); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment