subscribeToConnectivityChange method

dynamic subscribeToConnectivityChange({
  1. required dynamic subscriptionCallback(
    1. Stream<ConnectivityWatcherStatus> stream
    ),
})

subscriptionCallback The method is use to subscribe to the internet changes method can be used to call apis on network changes

Implementation

subscribeToConnectivityChange(
    {required Function(Stream<ConnectivityWatcherStatus> stream)
        subscriptionCallback}) {
  WidgetsBinding.instance.addPostFrameCallback((_) async {
    Stream<ConnectivityWatcherStatus> stream = currentContext
        .dependOnInheritedWidgetOfExactType<ConnectivityInheritedWidget>()!
        .controller!
        .connectivityController
        .stream;
    subscriptionCallback(stream);
  });
}