Closed igoooor closed 6 years ago
Can you give me the line number which throws this error?
it comes from the function Persistor.createMiddleware()
, line 77
Published 0.7.0-rc.2
. Should fix this.
Let me know if everything is good! If so, I'll push it as 0.7.0
.
I have the same problem with 0.7.0-rc2 :/
the error is a bit different
type '(Store<AppState>, dynamic, (dynamic) => void) => Null' is not a subtype of type '(Store<dynamic>, dynamic, (dynamic) => void) => void'
Seems like you are returning Null
somewhere instead of void?
Me? I don't think. I think the reason is that the package uses dart redux 2.x and I use redux 3.x
Were you able to solve this? I'm having the exact same issue here.
type '(Store
When calling: persistor.createMiddleware()
This is very odd, as I can't really reproduce this.
Can you give me a full example that I can run to reproduce this?
If I change this (in redux_persist.dart):
Middleware<T> createMiddleware() =>
(Store<T> store, dynamic action, NextDispatcher next) {
next(action);
if (action is! PersistAction) {
try {
// Save
save(store);
} catch (_) {}
}
};
to this:
Middleware<T> createMiddleware(){
return middlewareHandler;
}
void middlewareHandler
(Store<T> store, dynamic action, NextDispatcher next) {
next(action);
if (action is! PersistAction) {
try {
// Save
save(store);
} catch (_) {}
}
}
The error goes away.
Using: flutter 0.5.1, redux 3.0.0
Hey! Try again using the latest versions and let me know how it goes for you!
Hey again @Cretezy! I'm having this problem now. My code is divided in two files and that seems to be an issue:
File Store:
final Persistor<AppState> persistor = Persistor<AppState>(
storage: FlutterStorage(key: 'flutter_boot'),
serializer: JsonSerializer<AppState>(AppState.persistorSerializer),
);
final AppState initial = await persistor.load();
final Store<AppState> store = Store(
appReducer,
middleware: createMiddleware(persistor),
initialState: initial ?? AppState(),
);
return store;
}
return <Middleware<AppState>>[
persistor.createMiddleware(),
thunkMiddleware,
new LoggingMiddleware.printer(
formatter: LoggingMiddleware.multiLineFormatter,
),
];
}
And if I do this, it starts to work:
final Persistor<AppState> persistor = Persistor<AppState>(
storage: FlutterStorage(key: 'flutter_boot'),
serializer: JsonSerializer<AppState>(AppState.persistorSerializer),
);
final AppState initial = await persistor.load();
final Store<AppState> store = Store(
appReducer,
middleware: [
persistor.createMiddleware(),
thunkMiddleware,
new LoggingMiddleware.printer(
formatter: LoggingMiddleware.multiLineFormatter,
),
],
initialState: initial ?? AppState(),
);
return store;
}
The problem seems to be that the persistor.createMiddleware()
needs to be in the same file as the creation of the store but that doesn't make sense.
Could you help please? Thanks! :)
I had the same issue recently, but it was a problem with generics. I used the type as Persistor
instead of Persistor<AppState>
. Declaring the generic type made the difference.
Having the same issue with the following code:
return Store(
appReducer,
middleware: Middleware<AppState>[
persistor.createMiddleware(),
...createMiddlewares(injectedServices),
],
initialState: initialState ?? AppState.defaultState(),
distinct: true,
);
I had persistor
declared in another file and passed it over.
Once I moved persistor
into the same file the issue went away ¯_(ツ)_/¯
When running the following portion of code
I receive the following error
type '(Store<AppState>, dynamic, (dynamic) => void) => Future<Null>' is not a subtype of type '(Store<dynamic>, dynamic, (dynamic) => void) => void'
Here are my dependencies
And I correctly followed all migration steps (yours and the one of flutter_redux). On a side note, I had it perfectly working until the migration of my code to Dart 2 and your RC.