Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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,
      ),
    ),
like image 706
M Imtiaz Avatar asked Jan 24 '26 01:01

M Imtiaz


2 Answers

ChangeNotifierProxyProvider<Auth, Products>(
      create: (_) => Products('', '', []),
      update: (_, auth, prevProducts) {
        return Products(
          auth.token,
          auth.userId,
          prevProducts == null ? [] : prevProducts.items,
        );
      },
    ),
like image 69
Arun Avatar answered Jan 25 '26 18:01

Arun


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: ...
);
like image 44
Viren V Varasadiya Avatar answered Jan 25 '26 16:01

Viren V Varasadiya



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!