Flutter "ChangeNotifierProxyProvider have an error. error: "The named parameter 'builder' isn't defined. "

Issue

main.dart file ChangeNotifierProxyProvider having issues builder method is not defined.

 ChangeNotifierProxyProvider<Auth, Orders>(
      builder: (ctx, auth, previousOrders) => Orders(
        auth.token,
        auth.userId,
        previousOrders == null ? [] : previousOrders.orders,
      ),
    ),

Solution

Their is no argument like builder in ChangeNotifierProxyProvider, that’s why you are getting that error.

In ChangeNotifierProxyProvider you have to provide create, update and child.

Here, in create you can create your object and in update you can specify when to change provider’s value, when notifier depends on some other model.

ChangeNotifierProxyProvider<MyModel, MyChangeNotifier>(
   create: (_) => MyChangeNotifier(),
   update: (_, myModel, myNotifier) => myNotifier
       ..update(myModel),
    child: ...
);

Answered By – Viren V Varasadiya

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published