You need to use the dispose() method of State or the default constructor of ChangeNotifierProvider . The latter automatically disposes of the object created in the create function.
Read moreWhat is a dart provider?
A Provider that manages the lifecycle of the value it provides by delegating to a pair of Create and Dispose . It is usually used to avoid making a StatefulWidget for something trivial, such as instantiating a BLoC.
Read moreHow do I get rid of ChangeNotifier in Flutter?
dispose method Null safety Discards any resources used by the object. After this is called, the object is not in a usable state and should be discarded (calls to addListener and removeListener will throw after the object is disposed). This method should only be called by the object’s owner .
Read moreWhat is Consumer Flutter?
Consumer is an object in the Provider library that offers a simple API to interact with your provided models in the widgets themselves . In plain English, Consumer exposes instances of provided models, so you can display data and call methods on your provided model.
Read more