1

I have a MultiProvider with a list of one ChangeNotifierProvider for AuthProvider (this a class with NotifierProvider) and a ChangeNotifierProxyProvider for <AuthProvider, AppProvider>.

MultiProvider image

As you can see, in the update closure of the ChangeNotifierProxyProvider i am getting an error that says:

"The return type 'AppProvider?' isn't a 'AppProvider', as required by the closure's context. 
The method 'update' can't be unconditionally invoked because the receiver can be 'null'.
Try making the call conditional (using '?.') or adding a null check to the target ('!')."

And the type of parameter received in the closure is AppProvider?.

AppProvider? type in update

If I add the null check ! or conditional access ? to the object's update() method call, passes the linter bat throws a compile time error.

What am I doing wrong?

pedrozopayares
  • 2,856
  • 1
  • 13
  • 14

1 Answers1

0

This worked for me:

update: (_, myModel, myNotifier) => myNotifier!..update(myModel),

I got that from the question part of another stack overflow. It feels really wrong, but it seems to work and can't find a better answer.

The other post: ChangeNotifierProxyProvider is giving a possible null error

Gabriel Deml
  • 164
  • 2
  • 6