plus_plugins icon indicating copy to clipboard operation
plus_plugins copied to clipboard

[Bug]: PlatformException: NetworkManager::StartListen when using onConnectivityChanged on Windows

Open MrRoy121 opened this issue 3 months ago • 3 comments

Platform

Windows 11 (also occurs on Windows 10)

Plugin

connectivity_plus

Version

7.0.0

Flutter SDK

3.35.7

Steps to reproduce

  1. Create a new Flutter project with Windows support: flutter create -p windows my_app
  2. Add connectivity_plus: ^6.0.5 to pubspec.yaml
  3. Run flutter pub get
  4. Replace lib/main.dart with the code sample below
  5. Run on Windows: flutter run -d windows
  6. Observe the PlatformException being thrown in the console

The error occurs immediately when the app tries to listen to connectivity changes.

Code Sample

**main.dart:**

import 'package:flutter/material.dart';
import 'package:connectivity_plus/connectivity_plus.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Connectivity Test',
      home: const ConnectivityTestScreen(),
    );
  }
}

class ConnectivityTestScreen extends StatefulWidget {
  const ConnectivityTestScreen({Key? key}) : super(key: key);

  @override
  State<ConnectivityTestScreen> createState() => _ConnectivityTestScreenState();
}

class _ConnectivityTestScreenState extends State<ConnectivityTestScreen> {
  late StreamSubscription<List<ConnectivityResult>> _connectivitySubscription;
  String _status = 'Initializing...';

  @override
  void initState() {
    super.initState();
    _setupConnectivityListener();
  }

  void _setupConnectivityListener() {
    try {
      print('🔵 Setting up connectivity listener...');
      _connectivitySubscription = Connectivity().onConnectivityChanged.listen(
        (List<ConnectivityResult> result) {
          setState(() {
            _status = 'Connected: ${result.toString()}';
          });
          print('✅ Connectivity changed: $result');
        },
        onError: (error) {
          print('❌ Error in connectivity stream: $error');
          setState(() {
            _status = 'Error: $error';
          });
        },
      );
      print('✅ Listener setup successful');
    } catch (e) {
      print('❌ Exception during setup: $e');
      setState(() {
        _status = 'Setup failed: $e';
      });
    }
  }

  @override
  void dispose() {
    _connectivitySubscription.cancel();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Connectivity Plus Test')),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text('Status: $_status'),
            const SizedBox(height: 20),
            ElevatedButton(
              onPressed: () async {
                final result = await Connectivity().checkConnectivity();
                print('Single check result: $result');
              },
              child: const Text('Check Connectivity (Single)'),
            ),
          ],
        ),
      ),
    );
  }
}

Logs

🔵 Setting up connectivity listener...
======== Exception caught by services library ======================================================
The following PlatformException was thrown while activating platform stream on channel dev.fluttercommunity.plus/connectivity_status:
PlatformException(0, NetworkManager::StartListen, null, null)

When the exception was thrown, this was the stack: 
#0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:653:7)
#1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:367:18)
<asynchronous suspension>
#2      EventChannel.receiveBroadcastStream.<anonymous closure> (package:flutter/src/services/platform_channel.dart:712:11)
<asynchronous suspension>
#3      Stream.handleError.<anonymous closure> (dart:async/stream.dart:923:13)
<asynchronous suspension>

====================================================================================================

Flutter Doctor

PS C:\Users\RAHMAN\StudioProjects\sms> flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.35.7, on Microsoft Windows [Version 10.0.26200.7019], locale en-US)
[√] Windows Version (11 Home Single Language 64-bit, 25H2, 2009)
[!] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
    ! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
[√] Chrome - develop for the web
[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.14.9 (July 2025))
[√] Android Studio (version 2025.1.3)
[√] VS Code (version 1.105.1)
[√] Connected device (4 available)
[√] Network resources

! Doctor found issues in 1 category.
PS C:\Users\RAHMAN\StudioProjects\sms>

Checklist before submitting a bug

  • [x] I searched issues in this repository and couldn't find such bug/problem
  • [x] I Google'd a solution and I couldn't find it
  • [x] I searched on StackOverflow for a solution and I couldn't find it
  • [x] I read the README.md file of the plugin
  • [x] I'm using the latest version of the plugin
  • [x] All dependencies are up to date with flutter pub upgrade
  • [x] I did a flutter clean
  • [x] I tried running the example project

MrRoy121 avatar Nov 09 '25 15:11 MrRoy121

I'm also facing the same issue!

metaspook avatar Nov 13 '25 04:11 metaspook

what's happening? why nobody replying? this is a serious issue my app is in production i can't implement any fix in development, users facing problems due to this!

metaspook avatar Nov 22 '25 04:11 metaspook

same issue on windows 11!!

ReneDuris avatar Nov 28 '25 23:11 ReneDuris