I have an app that gets the data from a FutureProvider
and everything is working fine. Except I can't change the state of other providers
in my app. And when I do, I get this error
type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'Map<String, bool>' of 'value'
Here are all my providers
that are needed for this example
final connectionTypeProvider = FutureProvider.autoDispose((_) async {
final ConnectionType connectionType = await kGetConnectionType();
return connectionType;
});
final loadFromDatabase =
StateProvider<Map<String, bool>>((_) => {"loadFromDatabase": false});
final userAuthProvider = StateProvider<Map<String, bool>>((_) => {
'signedIn': false,
'loaded': true,
'signInWasDissmised': false,
'userIsConnectedToInternet': true
});
And here is how I use it. Please, reference the comments in the code.
class GetPage extends ConsumerWidget {
const GetPage({@required this.appState});
final Map<String, bool> appState;
@override
Widget build(BuildContext context, ScopedReader watch) {
StateController<Map<String, bool>> fromDatabase = watch(loadFromDatabase);
StateController<Map<String, dynamic>> isConnected = watch(userAuthProvider);
return watch(connectionTypeProvider).when(
data: (data) {
if (data == ConnectionType.none) { // Until here it works just fine
// Check database for previous data and if there is, show it to the user
final String database = 'Data';
if (database.isNotEmpty) {
fromDatabase.state = { // Here the problem happens
...fromDatabase.state,
"loadFromDatabase": true
};
print(fromDatabase);
return Home();
} else {
isConnected.state = { // Here the problem happens
...isConnected.state,
'userIsConnectedToInternet': false
};
// ... Other code
So what's the problem and how can I solve it? Thanks
In your code:
And :
Change your StateController to
<Map<String, bool>>