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
Thanks for your answer. In the meanwhile, I solved it with another solution:
In the main.dart
file I now use ChangeNotifierProxyProvider
instead of ChangeNotifierProvider
for the depending provider:
// main.dart
return MultiProvider(
providers: [
ChangeNotifierProvider(builder: (_) => Auth()),
ChangeNotifierProxyProvider(
builder: (context, auth, previousMessages) => Messages(auth),
initialBuilder: (BuildContext context) => Messages(null),
),
],
child: MaterialApp(
...
),
);
Now the Messages provider will be rebuilt when the login state changes and gets passed the Auth Provider:
class Messages extends ChangeNotifier {
final Auth _authProvider;
List _messages = [];
List get messages => _messages;
Messages(this._authProvider) {
if (this._authProvider != null) {
if (_authProvider.loggedIn) fetchMessages();
}
}
...
}