import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:get/get.dart';

class NetworkStatus {
  NetworkStatus._();

  static final NetworkStatus _instance = NetworkStatus._();

  factory NetworkStatus() => _instance;

  final Connectivity _connectivity = Connectivity();

  RxBool isConnected = false.obs;

  void startListening() {
    _connectivity.onConnectivityChanged.listen((result) {
      isConnected.value = !result.contains(ConnectivityResult.none);
    });

    _connectivity.checkConnectivity().then((result) {
      isConnected.value = !result.contains(ConnectivityResult.none);
    });
  }
}
