简体   繁体   中英

Calling dispose function in stateless widget using provider

I maintain a state of a counter(let say) in a separate Singelton class I am using provider in my app and I want to reset that state when I pop the current screen widget will it be possible.

Note: I want to use the stateless widget as in stateful its possible but any idea about achieving this in stateless.Like some sort of dispose function in changeNotifier provider.

Any class extended with ChangeNotifier gets an Dispose function you can override.

Example:

class MyClass with ChangeNotifier {
      @override
      void dispose() {
        // dispose your stuff here
        super.dispose();
      }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM