Skip to content
Related Articles

Related Articles

Flutter – Detecting Online-Offline Status of Device

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 31 Jan, 2022

Flutter SDK is an open-source software development kit developed by Google. Sometimes, the features of your application require the device of the user to be online and if it is offline you should notify the user to turn on mobile data or connect to Wi-Fi to access the internet.

Approach:  Use the flutter package flutter_offline to check the current connectivity status of the user’s device.

Step 1: Navigate to pubspec.yaml file.

Open your project in VS Code and navigate to pubspec.yaml file:

Step 2: Add the dependency.

Now add the flutter_offline as dependency and save.

Step 3: Download the dependencies.

Open the terminal in VS Code and run

flutter pub get

Step 4: The Code.

We will use the OfflineBuilder widget provided by the flutter_offline package to detect the connectivity of the device.

Syntax:

(new) OfflineBuilder OfflineBuilder({
  Key? key,
  required Widget Function(BuildContext, ConnectivityResult, Widget) connectivityBuilder,
  Duration debounceDuration = kOfflineDebounceDuration,
  Widget Function(BuildContext)? builder,
  Widget? child,
  Widget Function(BuildContext)? errorBuilder,
})

Example:

Code block

Output:

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!