How to get device IP in Dart/Flutter

前端 未结 8 818
孤城傲影
孤城傲影 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:57

    This provides the IP addresses of all interfaces

    import 'dart:io';
    
    ...
    
      Future printIps() async {
        for (var interface in await NetworkInterface.list()) {
          print('== Interface: ${interface.name} ==');
          for (var addr in interface.addresses) {
            print(
                '${addr.address} ${addr.host} ${addr.isLoopback} ${addr.rawAddress} ${addr.type.name}');
          }
        }
      }
    

    See also https://api.dartlang.org/stable/2.0.0/dart-io/NetworkInterface-class.html

    0 讨论(0)
  • 2021-02-13 22:00

    Have you tried the device_info package?

    There is an example on querying device information in https://pub.dartlang.org/packages/device_info#-example-tab-

    0 讨论(0)
提交回复
热议问题