我正在尝试在Flutter Web应用程序中获取本地IP地址。在搜索互联网时,我遇到了这个包:get_ip
0.4.0 - 它声称在Web下工作。
我有这个函数:
Future<void> initPlatformState() async {
print("Test");
String ipAddress;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
ipAddress = await GetIp.ipAddress;
} on PlatformException {
ipAddress = 'Failed to get ipAddress.';
} on Exception {
print("Exception");
}
print("Ip: $ipAddress");
}
我在main.dart
的initState
方法中调用它。
控制台只输出了Test
,没有输出IP或Exception
。
有人已经使用过这个包吗?是否有其他方法可以在web应用程序中获取本地IP?
(我正在使用MacOS)