How to get device IP in Dart/Flutter

前端 未结 8 826
孤城傲影
孤城傲影 2021-02-13 21:01

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

8条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-13 21:52

    I guess you mean the local IP of the currently connected Wifi network, right?

    EDITED

    In this answer, I used to suggest using the NetworkInterface in 'dart:io', however NetworkInterface.list is not supported in Android (as pointed out by Mahesh). The wifi package provides that, but later this was incorporated to the flutter's connectivity plugin. In Oct/2020 the methods for that were moved from the connectivity to the wifi_info_flutter plugin.

    So just go for wifi_info_flutter and call await WifiFlutter().getWifiIP().


    By the way, you may also want to check if Wifi is available using the connectivity plugin in flutter/plugins. Here's an example of how to check if wifi is available.

提交回复
热议问题