首先感谢您检查我的问题。
我是一个初学者,我有以下代码:
ChangeNotifierProxyProvider<Auth, ImgProvider>(
builder: (ctx, auth, previousItem) => ImgProvider(
auth.token,
auth.userId,
previousItem == null ? [] : previousItem.items,
),
),
????????p
ChangeNotifierProxyProvider
?????????????。 ????:
ChangeNotifierProxyProvider<Auth, ImgProvider>(
update: (ctx, auth, previousItem) => ImgProvider(
auth.token,
auth.userId,
previousItem == null ? [] : previousItem.items,
),
??????????????'??????'????????。”
??“”:“???“????????”。 !
答案 0 :(得分:0)
解决方案是像这样更改它:
ChangeNotifierProxyProvider<Auth, ImgProvider>(
create: (ctx) => ImgProvider(),
update: (ctx, auth, previousItem) => previousItem
..receiveToken(
auth, previousItem == null ? [] : previousItem.items),
),
并在ImgProvider()中创建一个函数,如下所示:
void receiveToken(Auth auth, List<ImgVar> items) {
authToken = auth.token;
userId = auth.userId;
_items = items;
}