一、引入dart_ping
官网地址:https://pub.dev/packages/dart_ping
dependencies:
//可以实现在手机上Ping网址,就像在电脑上Ping一样
dart_ping: ^9.0.1
二、使用
final ping = Ping('baidu.com', count: 5);
ping.stream.listen((event) {
print(event);
});
三、打印结果
I/flutter (30375): PingResponse(seq:1, ip:39.156.66.10, ttl:50, time:28.7 ms)
I/flutter (30375): PingResponse(seq:2, ip:39.156.66.10, ttl:50, time:42.7 ms)
I/flutter (30375): PingResponse(seq:3, ip:39.156.66.10, ttl:50, time:45.6 ms)
I/flutter (30375): PingResponse(seq:4, ip:39.156.66.10, ttl:50, time:45.1 ms)
I/flutter (30375): PingResponse(seq:5, ip:39.156.66.10, ttl:50, time:39.1 ms)
I/flutter (30375): PingSummary(transmitted:5, received:5), time: 4007 ms