1

My question stems from the Flutter Documentation on simple state management,

... Note that we’re defining a builder that creates a new instance of CartModel. ChangeNotifierProvider is smart enough not to rebuild CartModel unless absolutely necessary. It also automatically calls dispose() on CartModel when the instance is no longer needed.

When does dispose() get called on some given ChangeNotifier model?

pakmanz
  • 11
  • 1

1 Answers1

0

You should call any dispose methods of any created instances which provide it in dispose method of the State class of StatefulWidget.

class Test extends StatefulWidget {
  ...
}

class _TestState extends State<Test> {
  final valueNotifier = VakueNotifier<int>(0);

  @override
  void dispose() {
    valueNotifier.dispose();  // dispose resources etc
    super.dispose();
  }
}

BambinoUA
  • 6,126
  • 5
  • 35
  • 51