'Application Crashes at this point of code

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)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source