Detecting Internet Connectivity

In this article, we'll explore how to use the internet_connection_checker_plus package in FlutterFlow Community to detect internet connectivity in a Flutterflow application.

Steps:

  1. Adding the Package:

Firstly, you'll need to add the internet_connection_checker_plus package to your pubspec.yaml file. You can do this by adding the following line under dependencies:

flutter internet_connection_checker_plus:

  1. Writing the Code:

Now, you can use the package in your application. create a Custom Action and type this code:

// Automatic FlutterFlow imports
import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart';
import '/custom_code/actions/index.dart'; // Imports other custom actions
import '/flutter_flow/custom_functions.dart'; // Imports custom functions
import 'package:flutter/material.dart';
// Begin custom action code
// DO NOT REMOVE OR MODIFY THE CODE ABOVE!

import 'package:internet_connection_checker_plus/internet_connection_checker_plus.dart';

Future<bool> connect() async {
  // check internet connection
  bool isConnected = await InternetConnection().hasInternetAccess;
  return isConnected;
}

In this code, we create a function checkInternetConnectivity that checks the internet connectivity status and returns a boolean value (true if there's internet access and false otherwise).


Does this work for you? If there's anything else you need, feel free to ask!

16
2 replies