0
votes

The flutter application throws an exception in the first for loop and the app crashes after a few clips. I suspect that the error is with the super.dispose but I am unable to fix the said issue.

 @override
  void dispose() {
    try {
      if (model.clientList != null) {
        for (int i = 0; i < model.clientList.length; i++) {
          model.clientList.elementAt(i).unsubscribe("v1/devices/me/attributes");
          model.clientList
              .elementAt(i)
              .unsubscribe("v1/devices/me/attributes" + "/response/+");
          model.clientList.elementAt(i).autoReconnect = false;
          model.clientList.elementAt(i).disconnect();
        }
      }
    } on Exception catch (e) {
      print(e);
    }
    super.dispose();
  }

Below is the unsubscribe function

 void unsubscribe(String topic, {expectAcknowledge = false}) {
    subscriptionsManager!
        .unsubscribe(topic, expectAcknowledge: expectAcknowledge);
  }

The exception thrown is as following

_CastError (Null check operator used on a null value)
Please post the exception. We cannot fix "an error", we con only fix specific errors.nvoigt