Updated article : https://flatteredwithflutter.com/how-to-use-stream-provider-in-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.
Next, we need to import the packages in the dart file.
Now, we need to use the Connectivity class from this package. (Don’t worry below I have attached the program 🙂 ).
The _connectionSubscription is a stream that listens for the internet connections(wifi or mobile data) in the mobile.
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
In case of no internet, we get as
In the final app, on the button click I have updated the text with mobile internet status:
Similarly, in case of no net 🙁
Video Demonstration :
Complete Source Code : https://github.com/AseemWangoo/flutter_programs/blob/master/InternetConnectivity.dart