I am trying to check for connectivity result. If the connection is none then open dialog. But the problem is when I' am open mt home.dart the dialog always pop up first but when I close my wifi the dialog still show I don’t understand why

Code: home.dart

Map source = {ConnectivityResult.none: false};
final MyConnectivity connectivity = MyConnectivity.instance;

@override
  void initState() {
    connectivity.initialise();
    connectivity.myStream.listen((source) {
      setState(() => source = source);
    });
    super.initState();
}

 @override
  void dispose() {
    connectivity.disposeStream();
    super.dispose();
  }

    WidgetsBinding.instance.addPostFrameCallback((_) {
      switch (source.keys.toList()[0]) {
        case ConnectivityResult.mobile:
          break;
        case ConnectivityResult.wifi:
          break;
        case ConnectivityResult.none:
           default:
          openDialog4();
      }
    });

   return Scaffold(...);

//Connectivity class
   class MyConnectivity {
  MyConnectivity._();

  static final _instance = MyConnectivity._();
  static MyConnectivity get instance => _instance;
  final _connectivity = Connectivity();
  final _controller = StreamController.broadcast();
  Stream get myStream => _controller.stream;

  void initialise() async {
    ConnectivityResult result = await _connectivity.checkConnectivity();
    _checkStatus(result);
    _connectivity.onConnectivityChanged.listen((result) {
      _checkStatus(result);
    });
  }

  void _checkStatus(ConnectivityResult result) async {
    bool isOnline = false;
    try {
      final result = await InternetAddress.lookup('example.com');
      isOnline = result.isNotEmpty && result[0].rawAddress.isNotEmpty;
    } on SocketException catch (_) {
      isOnline = false;
    }
    _controller.sink.add({result: isOnline});
  }

  void disposeStream() => _controller.done;
}

If you guys know or have a better solution plz help. Thank you.