Member-only story
How To Use ChangeNotifier
It can’t be used in certain cases. Not directly anyway.
Have you ever tried to use the ChangeNotifier as a Mixin on a State class? You can’t do it.
class NotifierState extends State<NotifierWidget> with ChangeNotifier;
If you try, your State class will no longer call its dispose() method, and you need to call its dispose() method to ‘clean’ things up in many cases. However, the ChangeNotifier is a Mixin with its own dispose() method, and it doesn’t extend a parent class with a dispose() function. Therefore, as you can see in the second screenshot below, its dispose() method doesn’t have to call, super.dispose()
. It just won’t work as a Mixin on any class that has its own dispose() method. However, there is a way to introduce a ChangeNotifier with a Mixin by doing it indirectly.
Table of Contents
· Change the Mix
· The Field of Change
· Add Some Class
· Build Change
· Listen For Change