Tracks network connection.
Depends on connectivity_plus.
dependencies:
flutter_use_network_state: class Sample extends HookWidget {
@override
Widget build(BuildContext context) {
final networkState = useNetworkState();
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const Text("-- Network --"),
Text("fetched: ${networkState.fetched}"),
Text(
"connectivityResult: ${networkState.connectivityResult}"),
],
),
),
);
}
}fetched: bool- whether network connection state is fetched;connectivity: ConnectivityResult- network connection state changes.wifi- Device connected via Wi-Fi.ethernet- Device connected to ethernet network.mobile- Device connected to cellular network.none- Device not connected to any network.