I'm kinda confused as to what exactly the aim is with hooks_riverpod, I've used flutter_riverpod, and I've used flutter_hooks, but what is hooks_riverpod, on the pub.dev main page for hooks_riverpod, it's documentation is just flutter_riverpod documentation, there's not a single mention of hooks, and it's basically the same syntaxes and functionality?, I'm super confused, is this a troll package?, when I import hooks_riverpod into my project and remove flutter_riverpod, there are no errors, it just works with my former flutter_riverpod code. How and what is hooks riverpod and where is the documentation, how does it do anything different than flutter_riverpod since flutter riverpod basically even has full hook capabilities with extra features, what's the point of this combination and where is the evidence of the hooks added to the flutter_riverpod
Is there a use for hooks_riverpod
926 views Asked by public static void Main At
2
There are 2 answers
2
On
You can always check the source code of an open source package.
It is basically a re-export of flutter_riverpod with 3 additional classes which allow you to access the WidgetRef object and use hooks within the same widget.
- HookConsumerWidget
- StatefulHookConsumerWidget
- HookConsumer
The
flutter_hookspackage allows you to use hooks like:useEffect,useState,useAnimation,useTextEditingControllerand others. The full list is presented here Existing hooks.As an example, we could use hooks to manually implement a fade-in animation, where a widget starts invisible and slowly appears.
If we were to use StatefulWidget, the code would look like this:
Using hooks, the equivalent would be:
Note that we use the
HookWidgetclass, which allows you to use hooks inside thebuildmethod. But at the same time, we do not haveWidgetRef refas an argument to thebuildmethod.And it is the package
hooks_riverpodthat gives us the widgetHookConsumerWidgetthat allows us to use hooks in thebuildmethod, and also hasWidgetRef refas an argumentYou can read more about it here