I am currently writing an app where the user needs to know the IP address of their phone/tablet. Where would I find this information?
I only want to know what the local
You can use the wifi package for getting the local IP Address (for eg. 192.168.x.x). (as The NetworkInterface.list (from dart:io) is no longer supporting Android from 7.0 and above).
Use the wifi package :
import 'package:wifi/wifi.dart';
You can retrieve the IP Address like this:
Future getIp() async {
String ip = await Wifi.ip;
return ip;
}
You can display it on a Text widget using FutureBuilder:
FutureBuilder(
future: getIp(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return Center(child: CircularProgressIndicator());
} else {
if (snapshot.hasError)
return Center(child: Text('Error: ${snapshot.error}'));
else
return Center(child: Text('IP Address is : ${snapshot.data}')); //IP Address
}
},
);