Answers for "check if internet connected flutter"

1

flutter check internet connection

import 'package:connectivity/connectivity.dart';

var connectivityResult = await (Connectivity().checkConnectivity());
if (connectivityResult == ConnectivityResult.mobile) {
  // I am connected to a mobile network.
} else if (connectivityResult == ConnectivityResult.wifi) {
  // I am connected to a wifi network.
}


//connectivity: any
Posted by: Guest on June-04-2020
1

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');
}
Posted by: Guest on April-29-2021

Code answers related to "check if internet connected flutter"

Browse Popular Code Answers by Language