我正在使用fish redux在列表页中加载更多内容,这是刷新代码的一部分:
child: SmartRefresher(
onRefresh: () {
Future.delayed(Duration(milliseconds: 1000));
articleRequest.latestTime =
DateTime.now().millisecondsSinceEpoch;
_refreshController.refreshCompleted();
},
enablePullUp: true,
enablePullDown: true,
controller: _refreshController,
onLoading: () {
articleRequest.pageNum = articleRequest.pageNum + 1;
articleRequest.latestTime =
DateTime.now().millisecondsSinceEpoch;
dispatch(ChannelListDefaultActionCreator.onLoadingChannels(
articleRequest));
_refreshController.loadComplete();
},
}
SmartRefresher
组件加载事件时,我触发一个dispath以更改为组件状态,并从服务器触发一个新的获取请求。这是调度代码:
onLoading: () {
articleRequest.pageNum = articleRequest.pageNum + 1;
articleRequest.latestTime =
DateTime.now().millisecondsSinceEpoch;
dispatch(ChannelListDefaultActionCreator.onLoadingChannels(
articleRequest));
_refreshController.loadComplete();
}
这就是
action.dart
代码:
import 'package:Cruise/src/models/request/article/article_request.dart';
import 'package:fish_redux/fish_redux.dart';
//TODO replace with your own action
enum ChannelListDefaultAction { action, loading_channels }
class ChannelListDefaultActionCreator {
static Action onAction() {
return const Action(ChannelListDefaultAction.action);
}
static Action onLoadingChannels(ArticleRequest request) {
return Action(ChannelListDefaultAction.loading_channels,payload: request);
}
}
这就是
reducer.dart
代码:
import 'package:Cruise/src/models/request/article/article_request.dart';
import 'package:fish_redux/fish_redux.dart';
import 'action.dart';
import 'state.dart';
Reducer<ChannelListDefaultState> buildReducer() {
return asReducer(
<Object, Reducer<ChannelListDefaultState>>{
ChannelListDefaultAction.action: _onAction,
ChannelListDefaultAction.loading_channels: _onLoadingChannels,
},
);
}
ChannelListDefaultState _onAction(
ChannelListDefaultState state, Action action) {
final ChannelListDefaultState newState = state.clone();
return newState;
}
ChannelListDefaultState _onLoadingChannels(
ChannelListDefaultState state, Action action) {
final ChannelListDefaultState newState = state.clone();
ArticleRequest newReq = (action.payload as ArticleRequest);
newState.articleRequest = newReq;
return newState;
}
flutter: [debug] Capture from onError NoSuchMethodError: The method 'call' was called on null.
Receiver: null
Tried calling: call()
======== Exception caught by foundation library ====================================================
The following NoSuchMethodError was thrown while dispatching notifications for ValueNotifier<LoadStatus>:
The method 'call' was called on null.
Receiver: null
Tried calling: call()
When the exception was thrown, this was the stack:
#0 ConnOp.set (package:fish_redux/src/redux_connector/connector.dart:19:43)
#1 MutableConn.subReducer.<anonymous closure> (package:fish_redux/src/redux/connector.dart:94:9)
#2 combineSubReducers.<anonymous closure> (package:fish_redux/src/redux/combine_reducers.dart:15:46)
#3 combineReducers.<anonymous closure> (package:fish_redux/src/redux/combine_reducers.dart:45:26)
#4 _appendUpdateStateReducer.<anonymous closure> (package:fish_redux/src/redux_component/batch_store.dart:100:44)
...
The ValueNotifier<LoadStatus> sending notification was: ValueNotifier<LoadStatus>#e760c(LoadStatus.loading)
====================================================================================================
我花了两天时间找出哪里出了问题。有人说我应该在连接器中实现set功能,然后我在连接器中添加了这个
ChannelListDefaultConnector
:
@override
void set(HomeListState state, ChannelListDefaultState subState) {
state.channelListDefaultState = subState;
}
但问题仍未解决。我应该怎么做来解决或避免这个问题?