You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter中ChangeNotifierProxyProvider提示update参数必填的问题求助

Solution for Missing 'update' Parameter Warning

This warning shows up because Provider package versions 6.0+ deprecated the builder parameter in ChangeNotifierProxyProvider and replaced it with the required update parameter. Your code is still using the old builder syntax, which triggers the missing required param alert.

Here's the straightforward fix:

Just replace the builder key with update in your ChangeNotifierProxyProvider definition. The logic inside the function stays exactly the same—only the parameter name needs to change.

Corrected Code:

return MultiProvider(
  providers: [
    ChangeNotifierProvider.value(
      value: Auth(),
    ),
    ChangeNotifierProxyProvider<Auth, Operatori>(
      // Swap 'builder' with 'update' here
      update: (ctx, auth, prevData) => Operatori(auth.token, auth.userId, prevData == null ? [] : prevData.operatori),
    ),
  ],
);

Why This Fixes the Warning:

  • In newer Provider versions, update is the mandatory parameter for defining how the proxy provider should refresh its value when the upstream provider (your Auth class here) changes.
  • You don't need to modify any of your existing logic—this is just a syntax update to align with the package's current requirements.

If you're on an older Provider version, you might not see this warning, but switching to update ensures your code stays compatible with future updates.

内容的提问来源于stack exchange,提问作者mrapi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 09:04:39