Flutter - ping google.com and get the latency in flutter

Viewed 1307

Anyone know how to ping google and get latency in Flutter? I am using dart_ping but fail to ping.

1 Answers

Try dart_ping:

Setup:

dependencies:
  dart_ping: ^1.0.0

Notes:

  • Watch the spacing. It should be excatly correct in the pubspec.yaml . You can add the second line (dart_ping: ^1.0.0) right below cupertino_icons: ^....
  • Remember to click on Packages Get (in Android Studio).

Usage:

import 'package:dart_ping/dart_ping.dart';

main() async {
  var stream = await ping("google.com", times: 5);

  print("Pinging google.com");
  stream.listen((d) {
    print(d.time.inMilliseconds);
  });
}
Related