Reputation: 33
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,
),
),
Upvotes: 3
Views: 2161
Reputation: 1143
with provider: ^5.0.0
this also should work as expected
ChangeNotifierProxyProvider<Auth, Products>(
create: (ctx) {
return Products();
},
update: (ctx, auth, prev) {
return Products()
..setAuthToken(auth.token ?? '')
..setItems(prev?.items ?? []);
},
),
Upvotes: 0
Reputation: 76
ChangeNotifierProxyProvider<Auth, Products>(
create: (_) => Products('', '', []),
update: (_, auth, prevProducts) {
return Products(
auth.token,
auth.userId,
prevProducts == null ? [] : prevProducts.items,
);
},
),
Upvotes: 6
Reputation: 11
ChangeNotifierProvider supported builder parameter but migration from v3.x.0 to v4.0.0+ some parameters are changed and builder is one of them.
Instead of that the initialBuilder should be replaced by create.
builder of "proxy" providers should be replaced by update
builder of classical providers should be replaced by create.
Upvotes: 1
Reputation: 27137
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: ...
);
Upvotes: 1