Internet connectivity in Flutter

Internet connectivity in Flutter

aseemwangoo No Comment
Flutter

Recently, I wrote a program related to the internet connectivity in flutter. I used a package from flutter named as “connectivity”.

Added connectivity: ^0.3.0 to pubspec.yaml.

Connectivity Package

Next, we need to import the packages in the dart file.

import ‘package:connectivity/connectivity.dart’;

Now, we need to use the Connectivity class from this package. (Don’t worry below I have attached the program 🙂 ).

Connectivity package

The _connectionSubscription is a stream that listens for the internet connections(wifi or mobile data) in the mobile.

ConnectionSubscription

In the _connectionStatus, we get the final output, for instance are we connected to wifi or mobile data. I have attached a log file from the program below

Mobile Network

In case of no internet, we get as

Without internet

 

In the final app, on the button click I have updated the text with mobile internet status:

Button click on with internet

 

Similarly, in case of no net 🙁

Button click with no internet.

Button click with no internet.

 

Gist……….

Video Demonstration :

Complete Source Code : https://github.com/AseemWangoo/flutter_programs/blob/master/InternetConnectivity.dart

P.S……………

Leave a Reply