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 more