Does autoDispose in riverpod works same as dispose lifecycle in Flutter?

1.3k views Asked by At

Does autoDispose in Riverpod's StateProvider disposes controllers? Does both the following statements works similarly?

final _controller = StateProvider.autoDispose((ref) => PageController());

or

final _controller = PageController();
    
      @override
      void dispose() {
        _controller.dispose();
        super.dispose();
      }
1

There are 1 answers

0
abdelrahman abied On

autoDispose modifier, as the name suggests, disposes call of the resources when the provider is not used, it simply frees up memory without us specifying any dispose function.

One example that may help you for example when you navigate into another page in which you have a provider with autoDispose, if you go back to your first page your provider data will reset, without autoDispose, everything will be saved.