i started using Provider package for state management, and using it in a basic way. As the app gets more complex i want to extend the usage.
Now i have this model structure in mind: List<Client>
having a List<Product>
(and deeper having a List<Component>
).
I have a MultiProvider using a ChangeNotifierProvider for the Clients, means the List<Client>
is managed by the provider, so far so good.
Now i want to directly use the List<Product>
in a provider, or later the List<Component>
inside the List<Product>
. I do not want to go the way through the List<Client>
...down to the Component.
Here i have an image map of the structure to visualize.
Here is some simplified code:
// Just an example idea of..
Class Product with ChangeNotifier {
final String title;
}
Class Client with ChangeNotifier {
final String name;
final String List<Product>;
}
Class Clients with ChangeNotifier {
final List<Client> _items;
}
void main() {
// start the app
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MultiProvider(
providers: [
ChangeNotifierProvider(create: (ctx) => Clients()),
// How to provide a List<Product> that actually in the model
// belongs to a Client in the List<Client>
],
child: MaterialApp(
body: ...
)
);
}
}
So the main question is how to provide a List<Product>
that actually in the model
belongs to a Client in the List<Client>
?