1.列表,筛选完成和未完成
2.详情,增加checkout
This commit is contained in:
63
lib/page/plan/history/viewmodel/plan_list_store.dart
Normal file
63
lib/page/plan/history/viewmodel/plan_list_store.dart
Normal file
@@ -0,0 +1,63 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:plan/api/dto/plan_item_dto.dart';
|
||||
import 'package:plan/api/endpoints/plan_api.dart';
|
||||
|
||||
///筛选已完成和没完成
|
||||
class PlanStatusFilter {
|
||||
bool archived;
|
||||
bool unarchived;
|
||||
|
||||
PlanStatusFilter({required this.archived, required this.unarchived});
|
||||
|
||||
PlanStatusFilter copyWith({
|
||||
bool? archived,
|
||||
bool? unarchived,
|
||||
}) {
|
||||
return PlanStatusFilter(
|
||||
archived: archived ?? this.archived,
|
||||
unarchived: unarchived ?? this.unarchived,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class PlanListStore extends ChangeNotifier {
|
||||
bool isInit = true;
|
||||
|
||||
///原始数据
|
||||
List<PlanItemDto> _originList = [];
|
||||
|
||||
List<PlanItemDto> get planList => _originList;
|
||||
|
||||
///显示已完成和未完成
|
||||
PlanStatusFilter planStatus = PlanStatusFilter(archived: true, unarchived: true);
|
||||
|
||||
PlanListStore() {
|
||||
getPlanList();
|
||||
}
|
||||
|
||||
Future<void> getPlanList() async {
|
||||
_originList = await getPlanListApi();
|
||||
isInit = false;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
///修改状态
|
||||
void setPlanStatus(PlanStatusFilter planStatus) {
|
||||
this.planStatus = planStatus;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
///更新子项
|
||||
void updateStep(PlanItemDto newStep) {
|
||||
final int index = _originList.indexWhere((e) => e.id == newStep.id);
|
||||
if (index != -1) {
|
||||
_originList[index] = newStep; // 引用变了 → 框架感知
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
///移除子项
|
||||
void removeStep(PlanItemDto step) {
|
||||
_originList.removeWhere((e) => e.id == step.id);
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user