0

I want do this (not possible):

class Model1 extends ChangeNotifier {
...
  final List<Item> items = [];
}


class Model2 extends ChangeNotifier {

void performOperation() {
//Access items from Model1 here
final newItems = Provider.of<Model1>(context).items,
...
}


}

It seem suggestion is use ChangeNotifierProxyProvider
But this seem very inefficient. Why I must create another layer with ChangeNotifierProxyProvider if I am not yet use this value in UI? I just want mix Model1 and Model2 for business logic here.

Thanks for help!

FlutterFirebase
  • 2,163
  • 6
  • 28
  • 60

1 Answers1

0

One model can't access another model using provider because models are not widgets, they know nothing about providers and contexts.
If you don't want to use ChangeNotifierProxyProvider, you might extract shared logic to separate class or method and reuse it inside models.

Mikhail Ponkin
  • 2,563
  • 2
  • 19
  • 19