'Flutter Riverpod call StateProvider within a class that itself is a StateProvider

I have a Class that is being called by Widgets but this Class needs to pull data from another Class. Basically, I am using Riverpod as Dependency Injection, and am unsure if this is "correct" or am I doing it wrong. Here is what I did:

main.dart

var myClass1 = Class1();
final class1Provider = StateProvider((ref) => myClass1);
final class2Provider = StateProvider((ref) => Class2(myClass1));

Is this the recommended way or should I do something else?

FYI this does work;

Widget build(BuildContext context) {
  displayData = (ref.watch(class2Provider.notifier).state).getData();

thanks



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source