network_monitor_cp 0.0.6 copy "network_monitor_cp: ^0.0.6" to clipboard
network_monitor_cp: ^0.0.6 copied to clipboard

Connectivity_plus wrapper to monitor network status in rela time

A tiny package to monitor network status on real time. This is wrapper package around connectivity_plus.

Features #

You can monitor network status at following level

  1. Global level
  2. Screen level
  3. Widget level

Getting started #

to use this in your flutter application. intialize NetworkMonitor in main method.

await NetworkMonitor().initialize();

Usage #

to use it at global level define navigatorObservers parameter inside the material app.

navigatorObservers: [
        NetworkAwareNavigatorObserver(
          networkStatusScreen: const NetworkStatusScreen(),
          errorType: ErrorType.widget,
        )
      ],

to use at screen level you can use the mixin class

class _NetworkMonitorWidgetState extends State<NetworkMonitorWidget>
    with NetworkAwareMixin {
  @override
  void initState() {
    super.initState();
    initializeNetworkMonitoring((state) {
      switch (state) {
        case NetworkState.connected:
          debugPrint("connection state connected");

          break;
        case NetworkState.disconnected:
          debugPrint("connection state disconnected");

          break;
        case NetworkState.noInternet:
          debugPrint("connection state no internet");

          break;

        default:
      }
    });
  }

  @override
  void dispose() {
    super.dispose();
    disposeNetworkMonitoring();
  }

To use at widget level you can use the streambuilder

StreamBuilder<NetworkState>(
              stream: NetworkMonitor().state,
              builder: (context, snapshot) {
                // Build based on connection state
                return Text('Network status check ${snapshot.data?.name}');
              },
            ),

if you just want to ensure the connection is connected or not you can use this static method.

  final bool isConnected = await NetworkMonitor.isConnected();

Additional information #

Feel free to enhance the package by raising the PR and opening the issue.

0
likes
130
points
307
downloads

Publisher

unverified uploader

Weekly Downloads

Connectivity_plus wrapper to monitor network status in rela time

Repository (GitHub)
View/report issues

Documentation

API reference

License

unknown (license)

Dependencies

connectivity_plus, flutter

More

Packages that depend on network_monitor_cp