ChangeNotifierProvider vs ChangeNotifierProvider.value

后端 未结 4 1915
悲&欢浪女
悲&欢浪女 2020-12-17 15:24

I am quite new to this framework and working on state management using provider package where I come across ChangeNotifierProvider and ChangeNotifierProvi

4条回答
  •  抹茶落季
    2020-12-17 16:02

    Does the official documentation help?

    DO use ChangeNotifierProvider.value to provider an existing ChangeNotifier:

    ChangeNotifierProvider.value(
      value: variable,
      child: ...
    )
    

    DON'T reuse an existing ChangeNotifier using the default constructor.

    ChangeNotifierProvider(
      builder: (_) => variable,   
      child: ... 
    )
    

    Also check out this Github issue from the author about this.

提交回复
热议问题