我想你是说当前连接的Wifi网络的本地IP,对不对?
检查‘dart:io’中的NetworkInterface。
**编辑:Android不支持NetworkInterface.list,如稍后
Mahesh所指出的。除了答案中建议的wifi包之外,还有一个PR可以将其带到连接插件中。
您可能还想使用flutter /plugins中的连接插件检查Wifi是否可用。
在下面,有一个使用NetworkInferface的简单示例。
import 'dart:io';import 'package:flutter/material.dart';main() { runApp(new MyApp());}class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return new MaterialApp( title: "Network Interface example", home: new NetworkInterfaceWidget(), ); }}class NetworkInterfaceWidget extends StatefulWidget { @override _NetworkInterfaceState createState() => new _NetworkInterfaceState();}class _NetworkInterfaceState extends State<NetworkInterfaceWidget> { String _networkInterface; @override initState() { super.initState(); NetworkInterface.list(includeLoopback: false, type: InternetAddressType.any) .then((List<NetworkInterface> interfaces) { setState( () { _networkInterface = ""; interfaces.forEach((interface) { _networkInterface += "### name: ${interface.name}n"; int i = 0; interface.addresses.forEach((address) { _networkInterface += "${i++}) ${address.address}n"; }); }); }); }); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text("NetworkInterface"), ), body: Container( padding: EdgeInsets.all(10.0), child: Text("only in iOS.. :(nnNetworkInterface:n $_networkInterface"), ), ); }}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)