如何从列表中删除项目从州?

时间:2018-05-10 19:13:41

标签: redux dart flutter

我使用flutter redux进行状态管理。 但每当我使用reducer中的removeAt从列表中删除项目时,它总是删除该列表的最后一项。

状态:

class TimeTableState {
 final List<TimeTableModel> items;  
 TimeTableState({@required this.items});
 TimeTableState.initialState(): items = <TimeTableModel>[];
}

动作:

class DeleteAction {
 final TimeTableModel model;
 final int index;
 DeleteAction({@required this.model, @required this.index});
}

减速机:

else if(action is DeleteAction) {
  state.items.removeAt(action.index);
  return TimeTableState(
    items: state.items
  );
}

窗口小部件:

new StoreConnector<TimeTableState, ViewModel>(
 converter: (store) => new ViewModel.delete(
 deleteAction: (model, index) => 
  store.dispatch(DeleteAction(model: model, index: index))
 ),
 builder: (cxt, view) => 
   new Row(
    mainAxisAlignment: MainAxisAlignment.start,
    children: <Widget>[
     new IconButton(
     onPressed: () {
      view.deleteAction(viewModel[widget.index], widget.index);
     },
     icon: new Icon(Icons.delete),
     iconSize: 25.0,
     color: Colors.amber,
     )
    ],
   ),
  )

0 个答案:

没有答案