Skip to content

Latest commit

 

History

History
45 lines (38 loc) · 1.14 KB

useNetworkState.md

File metadata and controls

45 lines (38 loc) · 1.14 KB

useNetworkState

Tracks network connection.

Installation

Depends on connectivity_plus.

dependencies:
  flutter_use_network_state: ^0.0.2

Usage

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}"),
          ],
        ),
      ),
    );
  }
}

Reference

  • 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.