How to add this feature in Facebook Lite to the Flutter application, where this message appears when the Internet is cut off? See the image below show image
CodePudding user response:
Import connectivity_plus package and use below code.
import 'package:connectivity_plus/connectivity_plus.dart';
var connectivityResult = await (Connectivity().checkConnectivity());
if (connectivityResult != ConnectivityResult.mobile && connectivityResult != ConnectivityResult.wifi) {
//Internet is not connected
} else {
// Internet is connected
}
CodePudding user response:
With this package https://pub.dev/packages/connectivity_plus
var connectivityResult = await (Connectivity().checkConnectivity());
if (connectivityResult == ConnectivityResult.none) {
showDialog();
}
or you setup a listener and watch yor connectivitiy changes
subscription = Connectivity().onConnectivityChanged.listen((ConnectivityResult result) {
// Got a new connectivity status!
})