Gyft
Gyft

Reputation: 73

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

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();
      }

Upvotes: 0

Views: 1424

Answers (1)

abdelrahman abied
abdelrahman abied

Reputation: 297

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.

Upvotes: 2

Related Questions