Connectivity Listener

Connectivity Listener is a simple package that can be used to listen for changes in the connectivity.

Installation

dependencies:
  flutter:
    sdk: flutter
  connectivity_listener: ^0.0.1

Usage

import 'package:connectivity_listener/connectivity_listener.dart';
// The listener
final _connectionListener = ConnectionListener();

// Initialize the listener
@override
void initState() {
    super.initState();
    _connectionListener.init(
        onConnected: () => print("CONNECTED"),
        onReconnected: () => print("RECONNECTED"),
        onDisconnected: () => print("DISCONNECTED"),
    );
}

// Dispose the listener
@override
void dispose() {
    _connectionListener.dispose();
    super.dispose();
}

Methods

Method Description
init() Creates the listener. Has 3 parameters: onConnected, onReconnected, onDisconnected. These can be used to perform a function when the specific connection status is detected.
dispose() Should be called on dipose. This cleans up the active listener and cancels all subscriptions

Demo