skip to Main Content

This issue is only present when I navigate away from my ‘dashboard’ which is where most BLE operations are performed, and then navigate back to the ‘dashboard’ again

I/flutter (14996): [FBP] [[ OnCharacteristicReceived ]] result: {secondary_service_uuid: null, error_string: GATT_SUCCESS, service_uuid: feed1201-0451-4000-f00d-01140e3e79ae, success: 1, remote_id: 80:6F:B0:1E:FE:BB, error_code: 0, characteristic_uuid: feed0030-0451-4000-f00d-01140e3e79ae, value: 00}
I/flutter (14996): Power Status Received value: [0]
D/[FBP-Android](14996): [FBP] onCharacteristicRead: uuid: feed0013-0451-4000-f00d-01140e3e79ae status: 0
E/flutter (14996): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 4833 pos 12: '_lifecycleState != _ElementLifecycle.defunct': is not true.
E/flutter (14996): #0      _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:51:61)
E/flutter (14996): #1      _AssertionError._throwNew (dart:core-patch/errors_patch.dart:40:5)
E/flutter (14996): #2      Element.markNeedsBuild (package:flutter/src/widgets/framework.dart:4833:12)
E/flutter (14996): #3      State.setState (package:flutter/src/widgets/framework.dart:1158:15)
E/flutter (14996): #4      _DashboardViewState.GetPowerStatus.<anonymous closure>.<anonymous closure> (package:drc/view/dashboard.dart:432:17)
E/flutter (14996): #5      _RootZone.runUnaryGuarded (dart:async/zone.dart:1594:10)
E/flutter (14996): #6      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
E/flutter (14996): #7      _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
E/flutter (14996): #8      _SyncBroadcastStreamController._sendData (dart:async/broadcast_stream_controller.dart:377:25)
E/flutter (14996): #9      _BroadcastStreamController.add (dart:async/broadcast_stream_controller.dart:244:5)
E/flutter (14996): #10     _AsBroadcastStreamController.add (dart:async/broadcast_stream_controller.dart:474:11)
E/flutter (14996): #11     _RootZone.runUnaryGuarded (dart:async/zone.dart:1594:10)
E/flutter (14996): #12     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
E/flutter (14996): #13     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
E/flutter (14996): #14     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:784:19)
E/flutter (14996): #15     _StreamController._add (dart:async/stream_controller.dart:658:7)
E/flutter (14996): #16     _StreamController.add (dart:async/stream_controller.dart:606:5)
E/flutter (14996): #17     _RootZone.runUnaryGuarded (dart:async/zone.dart:1594:10)
E/flutter (14996): #18     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
E/flutter (14996): #19     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
E/flutter (14996): #20     _ForwardingStreamSubscription._add (dart:async/stream_pipe.dart:123:11)
E/flutter (14996): #21     _MapStream._handleData (dart:async/stream_pipe.dart:218:10)
E/flutter (14996): #22     _ForwardingStreamSubscription._handleData (dart:async/stream_pipe.dart:153:13)
E/flutter (14996): #23     _RootZone.runUnaryGuarded (dart:async/zone.dart:1594:10)
E/flutter (14996): #24     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
E/flutter (14996): #25     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
E/flutter (14996): #26     _ForwardingStreamSubscription._add (dart:async/stream_pipe.dart:123:11)
E/flutter (14996): #27     _WhereStream._handleData (dart:async/stream_pipe.dart:195:12)
E/flutter (14996): #28     _ForwardingStreamSubscription._handleData (dart:async/stream_pipe.dart:153:13)
E/flutter (14996): #29     _RootZone.runUnaryGuarded (dart:async/zone.dart:1594:10)
E/flutter (14996): #30     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
E/flutter (14996): #31     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
E/flutter (14996): #32     _ForwardingStreamSubscription._add (dart:async/stream_pipe.dart:123:11)
E/flutter (14996): #33     _WhereStream._handleData (dart:async/stream_pipe.dart:195:12)
E/flutter (14996): #34     _ForwardingStreamSubscription._handleData (dart:async/stream_pipe.dart:153:13)
E/flutter (14996): #35     _RootZone.runUnaryGuarded (dart:async/zone.dart:1594:10)
E/flutter (14996): #36     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
E/flutter (14996): #37     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
E/flutter (14996): #38     _ForwardingStreamSubscription._add (dart:async/stream_pipe.dart:123:11)
E/flutter (14996): #39     _WhereStream._handleData (dart:async/stream_pipe.dart:195:12)
E/flutter (14996): #40     _ForwardingStreamSubscription._handleData (dart:async/stream_pipe.dart:153:13)
E/flutter (14996): #41     _RootZone.runUnaryGuarded (dart:async/zone.dart:1594:10)
E/flutter (14996): #42     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
E/flutter (14996): #43     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
E/flutter (14996): #44     _ForwardingStreamSubscription._add (dart:async/stream_pipe.dart:123:11)
E/flutter (14996): #45     _WhereStream._handleData (dart:async/stream_pipe.dart:195:12)
E/flutter (14996): #46     _ForwardingStreamSubscription._handleData (dart:async/stream_pipe.dart:153:13)
E/flutter (14996): #47     _RootZone.runUnaryGuarded (dart:async/zone.dart:1594:10)
E/flutter (14996): #48     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
E/flutter (14996): #49     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
E/flutter (14996): #50     _ForwardingStreamSubscription._add (dart:async/stream_pipe.dart:123:11)
E/flutter (14996): #51     _MapStream._handleData (dart:async/stream_pipe.dart:218:10)
E/flutter (14996): #52     _ForwardingStreamSubscription._handleData (dart:async/stream_pipe.dart:153:13)
E/flutter (14996): #53     _RootZone.runUnaryGuarded (dart:async/zone.dart:1594:10)
E/flutter (14996): #54     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
E/flutter (14996): #55     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
E/flutter (14996): #56     _ForwardingStreamSubscription._add (dart:async/stream_pipe.dart:123:11)
E/flutter (14996): #57     _MapStream._handleData (dart:async/stream_pipe.dart:218:10)
E/flutter (14996): #58     _ForwardingStreamSubscription._handleData (dart:async/stream_pipe.dart:153:13)
E/flutter (14996): #59     _RootZone.runUnaryGuarded (dart:async/zone.dart:1594:10)
E/flutter (14996): #60     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
E/flutter (14996): #61     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
E/flutter (14996): #62     _ForwardingStreamSubscription._add (dart:async/stream_pipe.dart:123:11)
E/flutter (14996): #63     _WhereStream._handleData (dart:async/stream_pipe.dart:195:12)
E/flutter (14996): #64     _ForwardingStreamSubscription._handleData (dart:async/stream_pipe.dart:153:13)
E/flutter (14996): #65     _RootZone.runUnaryGuarded (dart:async/zone.dart:1594:10)
E/flutter (14996): #66     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
E/flutter (14996): #67     _DelayedData.perform (dart:async/stream_impl.dart:515:14)
E/flutter (14996): #68     _PendingEvents.handleNext (dart:async/stream_impl.dart:620:11)
E/flutter (14996): #69     _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:591:7)
E/flutter (14996): #70     _microtaskLoop (dart:async/schedule_microtask.dart:40:21)
E/flutter (14996): #71     _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)
E/flutter (14996): 
I/flutter (14996): Power Status Received value: [0]

Here is the code where this error is triggered:
The error is specifically talking about the setState call

Future<void> GetPowerStatus() async {
    if (cancel) {
      return;
    }
    try {
      powerControlChar.setNotifyValue(true).then((_) {
        if (powerControlChar.isNotifying) {
          if (cancel) {
            return;
          }
          powerControlChar.lastValueStream.listen((result) {
            // Handle the received value here
            int value = result[0];
            String binaryString = value.toRadixString(2);
            print('Power Status Received value: ${result}');
            if (result[0] == 1 || result[0] == 128) {
              if (mounted) {
                setState(() {
                  spinChannel1Icon = true;
                });
              }
            } else {
              if (mounted) {
                setState(() {
                  spinChannel1Icon = false;
                });
              }
            }
          });
        }
      });
    } catch(e) {
      print("Error in Sensor Status");
      print(e);
    }
  }

Here’s where I leave the dashboard:

void LeaveScreen() {
    subscription.cancel();
    cancel = true;
    feedTimer2.cancel();
    setState(() {
      loading = true;
    });
    disposeAsync();
    List<BluetoothService> services = Provider
        .of<AppData>(context, listen: false)
        .connectInfo["services"];
    Navigator.pushReplacement(context,
        MaterialPageRoute(
          builder: (context) => DRCListView(services),
          settings: RouteSettings(name: 'DRC List View'),
        ));
  }

Future<void> disposeAsync() async {
    await sensorStatusChar.setNotifyValue(false);
    await rssiChar.setNotifyValue(false);
    await powerControlChar.setNotifyValue(false);
  }

And here’s where I navigate to the dashboard:

  Future<void> ConnectPressed() async {
    setState(() {
      connecting = true;
    });
    // widget.ToggleConnecting();
    widget.cancelSubscription();
    Provider.of<AppData>(context, listen: false).changeCurrentDrcDetails({"name": widget.name, "id": widget.id, "index": widget.index});
    Provider.of<AppData>(context, listen: false).changeCurrentDrc("feed00");

    await WriteCharacteristic(widget.commandChar, [0x0A, widget.index, 0x01, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
    setState(() {
      connecting = false;
    });
    Navigator.pushReplacement(context,
        MaterialPageRoute(
          builder: (context) => DashboardView(widget.services),
          settings: RouteSettings(name: 'Dashboard View'),
        ));
  }

I tried adding some things to my dispose function on my dashboard but it is hitting an error everytime it is triggered

======== Exception caught by widgets library =======================================================
The following NoSuchMethodError was thrown while finalizing the widget tree:
Class '_BroadcastSubscription<BluetoothConnectionState>' has no instance method 'dispose'.
Receiver: Instance of '_BroadcastSubscription<BluetoothConnectionState>'
Tried calling: dispose()

When the exception was thrown, this was the stack: 
#0      Object.noSuchMethod (dart:core-patch/object_patch.dart:38:5)
#1      _DashboardViewState.dispose (package:drc/view/dashboard.dart:149:18)
#2      StatefulElement.unmount (package:flutter/src/widgets/framework.dart:5508:11)
#3      _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1952:13)
#4      _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1950:7)
#5      SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:6420:14)
#6      _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1948:13)
#7      _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1950:7)
#8      ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:5349:14)
#9      _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1948:13)
#10     _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1950:7)
#11     SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:6420:14)
#12     _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1948:13)
#13     _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1950:7)
#14     SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:6420:14)
#15     _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1948:13)
#16     _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1950:7)
#17     ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:5349:14)
#18     _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1948:13)
#19     _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1950:7)
#20     SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:6420:14)
#21     _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1948:13)
#22     _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1950:7)
#23     ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:5349:14)
#24     _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1948:13)
#25     _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1950:7)
#26     SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:6420:14)
#27     _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1948:13)
#28     _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1950:7)
#29     ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:5349:14)
#30     _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1948:13)
#31     _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1950:7)
#32     ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:5349:14)
#33     _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1948:13)
#34     _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1950:7)
#35     SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:6420:14)
#36     _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1948:13)
#37     _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1950:7)
#38     ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:5349:14)
#39     _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1948:13)
#40     _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1950:7)
#41     SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:6420:14)
#42     _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1948:13)
#43     _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1950:7)
#44     ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:5349:14)
#45     _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1948:13)
#46     _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1950:7)
#47     ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:5349:14)
#48     _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1948:13)
#49     _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1950:7)
#50     ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:5349:14)
#51     _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1948:13)
#52     _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1950:7)
#53     ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:5349:14)
#54     _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1948:13)
#55     _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1950:7)
#56     SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:6420:14)
#57     _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1948:13)
#58     _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1950:7)
#59     ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:5349:14)
#60     _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1948:13)
#61     _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1950:7)
#62     SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:6420:14)
#63     _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1948:13)
#64     _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1950:7)
#65     ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:5349:14)
#66     _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1948:13)
#67     _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1950:7)
#68     ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:5349:14)
#69     _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1948:13)
#70     _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1950:7)
#71     ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:5349:14)
#72     _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1948:13)
#73     _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1950:7)
#74     ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:5349:14)
#75     _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1948:13)
#76     _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1950:7)
#77     ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:5349:14)
#78     _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1948:13)
#79     _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1950:7)
#80     ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:5349:14)
#81     _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1948:13)
#82     _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1950:7)
#83     SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:6420:14)
#84     _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1948:13)
#85     _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1950:7)
#86     ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:5349:14)
#87     _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1948:13)
#88     _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1950:7)
#89     ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:5349:14)
#90     _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1948:13)
#91     _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1950:7)
#92     ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:5349:14)
#93     _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1948:13)
#94     _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1950:7)
#95     ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:5349:14)
#96     _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1948:13)
#97     _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1950:7)
#98     ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:5349:14)
#99     _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1948:13)
#100    _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1950:7)
#101    SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:6420:14)
#102    _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1948:13)
#103    _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1950:7)
#104    ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:5349:14)
#105    _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1948:13)
#106    _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1950:7)
#107    ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:5349:14)
#108    _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1948:13)
#109    _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1950:7)
#110    ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:5349:14)
#111    _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1948:13)
#112    _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1950:7)
#113    ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:5349:14)
#114    _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1948:13)
#115    ListIterable.forEach (dart:_internal/iterable.dart:39:13)
#116    _InactiveElements._unmountAll (package:flutter/src/widgets/framework.dart:1961:25)
#117    BuildOwner.lockState (package:flutter/src/widgets/framework.dart:2639:15)
#118    BuildOwner.finalizeTree (package:flutter/src/widgets/framework.dart:3049:7)
#119    WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:919:19)
#120    RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:360:5)
#121    SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1297:15)
#122    SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1227:9)
#123    SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:1085:5)
#124    _invoke (dart:ui/hooks.dart:170:13)
#125    PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:401:5)
#126    _drawFrame (dart:ui/hooks.dart:140:31)
====================================================================================================
 @override
  void dispose() {
    subscription.dispose();
    cancel = true;
    feedTimer2.cancel();
    disposeAsync();
    super.dispose();
  }

2

Answers


  1. Chosen as BEST ANSWER

    Alright, I found my problem, I simply created a variable of type StreamSubscription, I am then assigning the listener to this variable, and cancelling that StreamSubscription when navigating away from the screen.

    Here is the code:

    StreamSubscription? sensorStatusSubscription;
    
    Future<void> GetSensorStatus() async {
        if (cancel) {
          return;
        }
        try {
          sensorStatusChar.setNotifyValue(true).then((_) {
            if (sensorStatusChar.isNotifying) {
              sensorStatusSubscription = sensorStatusChar.lastValueStream.listen((result) {
                
                ...
    
              });
            }
          });
        } catch(e) {
          print("Error in Sensor Status");
          print(e);
        }
      }
    
    sensorStatusSubscription.cancel()
    

  2. wrap in

    WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
       
        });
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search