How to get device IP in Dart/Flutter

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

提交回复
热议问题