Internet connection check in flutter?

As a flutter developer, Whenever you develop an app the first thing is that is to check internet connection if there is internet resource then you have to fix it.

For it, dart packages provide a library named https://pub.dev/packages?q=data_connection_checker
It provides to check the internet connection available or not.
First, open the packages by given the link above the click the installation then add the dependencies in the pubspec.yaml

Then which dart class you want to add the check where import the dependency
then by the given readme instruction set up the method and apply the check

DataConnectionStatus status = await checkInternet();

if(status = DataConnectionStatus.connected){

//function that you want to perform

}else{

//whatever type you want to show the error like here I just used an alert box to show the no internet //message
showDialog(
  context: context,
  builder: (context)=>AlertDialog(
    shape: RoundedRectangleBorder(
      borderRadius: BorderRadius.all(Radius.circular(10.0)),
    ),
    title: Text("No Internet!"),
    content: Text("Check your internet connection."),
  )
);

}

Comments