What is the third input parameter in the Flutter ProxyProvider builder function

Issue

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?

Solution

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.

Answered By – Suragch

Answer Checked By – Marie Seifert (FlutterFixes Admin)

Leave a Reply

Your email address will not be published.