Hello Robert Jhon Gagui. Kuddos on learning flutter, I hope you are enjoying your journey so far.
Yeah, Inherited Widgets are immutable and you need to wrap it in a stateful widget, with a method (function) then that updates the state.
Exactly. Inherited widgets serve to inject state or values to your widget tree eliminating pop drilling.
Is ChangNotifierProvider better? The answer depends on what you want to do, if you have a value that does not change and you just want to provide it to your widget tree, going with InheritedWidgets will make sense and a better option will be to use Providers directly. If however your value changes then ChangeNotifierProvider will be better because
- InheritedWidgets have too much boilerplate code (which is cumbersome and difficult to maintain).
- InheritedWidgets can also be sometimes too nested, making factorization difficult and confusing.
- Nesting hell if for instance a widget depends on more than one InheritedWidget, wrapping that widget with those instances can be a drag.
Overall, ChangeNotifierProvider is a Provider and Providers have been built to be an upgrade of InheritedWidgets while adding certain flexes that make programmer's life easier and much fun.
You can read more of Providers here and ChangeNotifierProvider here.
You can take a look at my profile and see the progressive dissertations of flutter state management I have been writing, it may help you in your journey to learn StateManagement