flutter how to check if there network connection available code example

Example: check if internet connected flutter

The connectivity plugin states in its docs that it only provides information if 
there is a network connection, but not if the network is connected to the 
Internet

Note that on Android, this does not guarantee connection to Internet. For 
instance, the app might have wifi access but it might be a VPN or a hotel WiFi 
with no access. You can use

import 'dart:io';
...
try {
  final result = await InternetAddress.lookup('google.com');
  if (result.isNotEmpty && result[0].rawAddress.isNotEmpty) {
    print('connected');
  }
} on SocketException catch (_) {
  print('not connected');
}

Tags:

Dart Example