Im new in Flutter Framework and unable to find any replacement library for internet availability like we have Reachability in iOS. any help will be appreciated. Thanks.
3 Answers
You can build reactive layouts using a StreamBuilder
and the connectivity
plugin:
StreamBuilder(
stream: Connectivity().onConnectivityChanged,
builder: (BuildContext context, AsyncSnapshot<ConnectivityResult> result) {
if (result.data == ConnectivityResult.wifi)
return Text('wifi');
return Text('no wifi');
}
)
You can use connectivity plugin. This plugin works for iOS and Android.
Sample usage to check current status:
import 'package:connectivity/connectivity.dart';
var connectivityResult = await (new Connectivity().checkConnectivity());
if (connectivityResult == ConnectivityResult.mobile) {
// I am connected to a mobile network.
} else if (connectivityResult == ConnectivityResult.wifi) {
// I am connected to a wifi network.
}
-
1He posted it at the same time though. The code is coming from the plugin readme. Jun 20, 2018 at 11:05
-
1
you can use the following plugin to check connectivity
https://github.com/flutter/plugins/tree/master/packages/connectivity
import 'package:connectivity/connectivity.dart';
var connectivityResult = await (new
Connectivity().checkConnectivity());
if (connectivityResult == ConnectivityResult.mobile) {
// I am connected to a mobile network.
}. else if (connectivityResult == ConnectivityResult.wifi)
{
// I am connected to a wifi network.
}