How to use a provider inside of another provider in Flutter

前端 未结 4 976
遇见更好的自我
遇见更好的自我 2021-02-14 08:21

I want to create an app that has an authentication service with different permissions and functions (e.g. messages) depending on the user role.

So I create

4条回答
  •  -上瘾入骨i
    2021-02-14 08:40

    From version >=4.0.0, we need to do this a little differently from what @updatestage has answered.

    return MultiProvider(
      providers: [
        ChangeNotifierProvider(builder: (_) => Auth()),
        ChangeNotifierProxyProvider(
          update: (context, auth, previousMessages) => Messages(auth),
          create: (BuildContext context) => Messages(null),
        ),
      ],
      child: MaterialApp(
        ...
      ),
    );
    

提交回复
热议问题