什么会导致Flutter Redux StoreConnector无法重建

时间:2018-10-19 04:25:23

标签: redux dart flutter

#View
return ListView.builder(
            itemCount: eventIDs.length,
            itemBuilder: (BuildContext context, int i) {
              return StoreConnector<AppState, EventsPageViewModel>(
                  rebuildOnChange: true,
                  onDidChange: (EventsPageViewModel events) {print('${events}');},
                  onInit: (store) =>
                      store.dispatch(FetchEventAction(id: eventIDs[i])),
                  converter: (store) => EventsPageViewModel.fromStore(store),
                  builder: (BuildContext context, EventsPageViewModel events) {
                    print("build ListItem $i ${eventIDs[i]}");
                    if (events.events.containsKey('${eventIDs[i]}')) {
                      return EventCard(
                        event: events.events[eventIDs[i]],
                      );
                    }
                    return Container(
                      child: Card(
                        child: Container(
                          height: 120.0,
                        ),
                      ),
                    );
                  });
            },
          );
#State
@immutable
class Events {
  Events({
    this.loadingStatus,
    this.events,
  });

  factory Events.initial() {
    return Events(
      loadingStatus: Map<String, LoadingStatus>(),
      events: Map<String, EventModel>(),
    );
  }

  final Map<String, LoadingStatus> loadingStatus;
  final Map<String, EventModel> events;

  Events copyWith({
    Map<String, LoadingStatus> loadingStatus,
    Map<String, EventModel> events,
  }) {
    return Events(
      loadingStatus: loadingStatus ?? this.loadingStatus,
      events: events ?? this.events,
    );
  }

  @override
  bool operator ==(Object other) =>
      identical(this, other) ||
      other is Events &&
          runtimeType == other.runtimeType &&
          loadingStatus == other.loadingStatus &&
          const MapEquality().equals(events, other.events);

 @override
 int get hashCode => loadingStatus.hashCode ^ const MapEquality().hash(events);
}


#ViewModel
class EventsPageViewModel {
  EventsPageViewModel({
   @required this.status,
   @required this.events,
 });

 final Map<String, LoadingStatus> status;
 final Map<String, EventModel> events;

 static EventsPageViewModel fromStore(
   Store<AppState> store,
 ) {
   return EventsPageViewModel(
     status: store.state.events.loadingStatus,
     events: store.state.events.events,
   );
 }

 @override
 bool operator ==(Object other) =>
     identical(this, other) ||
     other is EventsPageViewModel &&
         runtimeType == other.runtimeType &&
         status == other.status &&
         const MapEquality().equals(events, other.events);

 @override
 int get hashCode => status.hashCode ^ const MapEquality().hash(events);
}

我试图在触发异步操作并向Map返回一个值后重建视图。我不知道我是否正确地进行了平等检查

我检查了中间件是否触发了GET请求。它是。 我检查了一下GET请求是否正在返回信息。它是。 我还有另一个异步动作正在触发。那将返回一个字符串列表,并在其StoreConnector上触发重建。

对于StoreConnector为什么未检测到差异,是否有人有任何线索?

0 个答案:

没有答案