Flutter problem with ChangeNotifierProxyProvider create

Viewed 3215

Since builder method of ChangeNotifierProxyProvider in flutter is deprecated i'm tring to implement create and update new methods of provider 4.

I need the main Auth Provider called User Provider inside another Provider(ContoProvider) on create but I have runtime error with Provider not found. All this provider are inside a Multiprovider in the main.dart file so the at the top of widget chain.

Probably this isn't the right method to pass the provider but i need in the create because i use it immediately

return MultiProvider(
  providers: [
    ChangeNotifierProvider<UserProvider>(
      create: (_) => UserProvider.init(),

    ),
    ChangeNotifierProxyProvider<UserProvider, ContoProvider>(
      create: (_) => ContoProvider.init(
        Provider.of<UserProvider>(context, listen: false),
      ),
      update: (_,  userProvider,  contoProvider) =>
          contoProvider..update(userProvider),
    ),
  ],child:..
1 Answers

Ok stupid error, i was referring to the wrong context for the Provider.of

I leave the question here for the implementation of create and update beacause there isn't a lot of example around

Related