0

Given a ProxyProvider like the following,

MultiProvider(
  providers: [
    ChangeNotifierProvider<MyModel>(
      builder: (context) => MyModel(),
    ),
    ProxyProvider<MyModel, AnotherModel>(
      builder: (context, myModel, anotherModel) => AnotherModel(myModel),
    ),
  ],

what is the third input parameter (anotherModel) in the builder function? The documentation doesn't explain it. If it is the same type as the returned function, why is it an input parameter?

Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
  • 1
    from the [official docs](https://pub.dev/documentation/provider/latest/provider/ProxyProvider-class.html): *"All variations of builder will receive the BuildContext as first parameter, and the previously built value as last parameter. This previously built value will be null by default, unless initialBuilder is specified – in which case, it will be the value returned by initialBuilder."* – pskink Oct 26 '19 at 07:28

1 Answers1

0

If you have a ProxyProvider like this:

ProxyProvider<MyModel, AnotherModel>(
  builder: (context, myModel, anotherModel) => AnotherModel(myModel),
)

As was mentioned in the comments and the docs, these are the parameter values:

  1. context: This is the BuildContext.
  2. myModel: This is a value that you are passing into the ProxiProvider to use as an input for the value that the builder returns.
  3. anotherModel: This is the last built value of the builder. The first time this value is null unless initialBuilder was specified.
Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393