我正在尝试将我的Firestore与Redux同步。我使用以下内容:
redux: "^3.0.0"
flutter_redux: "^0.5.0"
redux_logging: "^0.3.0"
redux_epics: "^0.9.0"
rxdart: "^0.16.7"
当我尝试将我的史诗添加到中间件时,我在这行代码中得到了这个错误:
final allEpics = combineEpics<AppState>([
ordersEpic,
]);
[dart]元素类型&#39;(Stream,EpicStore)→流&#39;无法分配到列表类型&#39;(Stream,EpicStore)→流&#39;。
史诗:
Stream<dynamic> ordersEpic(Stream<OrdersOnDataEventAction> actions, EpicStore<AppState> store){
return Observable(actions)
.ofType(TypeToken<RequestOrdersDataEventsAction>())
.switchMap((RequestOrdersDataEventsAction requestOrders){
return getOrders()
.map((orders)=>OrdersOnDataEventAction(orders))
.takeUntil(actions.where((action)=>action is CancelOrdersDataEventsAction));
});
}
Observable<List<DocumentSnapshot>> getOrders(){
return Observable(Firestore.instance.collection("orders").snapshots())
.map((QuerySnapshot q)=>q.documents);
}
操作
class RequestOrdersDataEventsAction{}
class CancelOrdersDataEventsAction{}
class OrdersOnDataEventAction{
final orders;
OrdersOnDataEventAction(this.orders);
}
订单
final ordersReducer = combineReducers<List<DocumentSnapshot>>([
TypedReducer<List<DocumentSnapshot>,OrdersOnDataEventAction>(_setOrders)
]);
List<DocumentSnapshot> _setOrders(List<DocumentSnapshot> oldOrders, OrdersOnDataEventAction action){
return action.orders;
}
答案 0 :(得分:0)
这听起来像是一个协方差问题。
typedef void myType(Stream<dynamic> s);
final list = List<myType>();
void myFunction(Stream<Order> s) {}
void myOtherFunction(Stream<dynamic> s) {}
// This gives the "(Stream<Order>) -> void not of expected type (Stream<dynamic>) -> void" error
list.add(myFunction);
// This works
list.add(myOtherFunction);
您是否尝试将动作参数的类型更改为动态?
Stream<dynamic> ordersEpic(Stream<dynamic> actions, EpicStore<AppState> store){