1.列表,筛选完成和未完成
2.详情,增加checkout
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:plan/api/dto/plan_item_dto.dart';
|
||||
import 'package:plan/api/endpoints/plan_api.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'widgets/history_item.dart';
|
||||
import 'widgets/loading_box.dart';
|
||||
import 'viewmodel/plan_list_store.dart';
|
||||
import 'widgets/custom_indicator.dart';
|
||||
import 'widgets/history_list.dart';
|
||||
import 'widgets/bar_actions.dart';
|
||||
|
||||
class PlanHistoryPage extends StatefulWidget {
|
||||
const PlanHistoryPage({super.key});
|
||||
@@ -14,81 +15,43 @@ class PlanHistoryPage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _PlanHistoryPageState extends State<PlanHistoryPage> {
|
||||
///是否显示删除
|
||||
bool _isDelete = false;
|
||||
|
||||
///数据
|
||||
List<PlanItemDto> _record = [];
|
||||
bool _isInit = true;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_onRefresh();
|
||||
}
|
||||
|
||||
///刷新
|
||||
Future<void> _onRefresh() async {
|
||||
var list = await getPlanListApi();
|
||||
setState(() {
|
||||
_record = list;
|
||||
_isInit = false;
|
||||
});
|
||||
}
|
||||
|
||||
///确认删除
|
||||
void _confirmDelete(int id) {
|
||||
setState(() {
|
||||
_record.removeWhere((element) => element.id == id);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CupertinoPageScaffold(
|
||||
backgroundColor: Theme.of(context).colorScheme.surfaceContainer,
|
||||
navigationBar: CupertinoNavigationBar(
|
||||
middle: const Text("Plan History"),
|
||||
),
|
||||
child: SafeArea(
|
||||
child: CustomScrollView(
|
||||
physics: AlwaysScrollableScrollPhysics(
|
||||
parent: BouncingScrollPhysics(),
|
||||
),
|
||||
slivers: <Widget>[
|
||||
//下拉刷新组件
|
||||
CupertinoSliverRefreshControl(
|
||||
onRefresh: _onRefresh,
|
||||
return ChangeNotifierProvider<PlanListStore>(
|
||||
create: (_) {
|
||||
return PlanListStore();
|
||||
},
|
||||
child: Consumer<PlanListStore>(
|
||||
child: SafeArea(
|
||||
child: CustomScrollView(
|
||||
physics: AlwaysScrollableScrollPhysics(
|
||||
parent: BouncingScrollPhysics(),
|
||||
),
|
||||
//列表
|
||||
LoadingBox(
|
||||
loading: _isInit,
|
||||
isEmpty: _record.isEmpty,
|
||||
child: ClipRRect(
|
||||
child: CustomScrollView(
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
slivers: [
|
||||
SliverList.separated(
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
return HistoryItem(
|
||||
item: _record[index],
|
||||
showDelete: _isDelete,
|
||||
onDelete: _confirmDelete,
|
||||
onInit: _onRefresh,
|
||||
);
|
||||
},
|
||||
separatorBuilder: (BuildContext context, int index) {
|
||||
return SizedBox(height: 15);
|
||||
},
|
||||
itemCount: _record.length,
|
||||
),
|
||||
],
|
||||
),
|
||||
slivers: <Widget>[
|
||||
//下拉刷新组件
|
||||
CustomIndicator(),
|
||||
//列表
|
||||
HistoryList(),
|
||||
],
|
||||
),
|
||||
),
|
||||
builder: (context, store, child) {
|
||||
return CupertinoPageScaffold(
|
||||
backgroundColor: Theme.of(context).colorScheme.surfaceContainer,
|
||||
navigationBar: CupertinoNavigationBar(
|
||||
middle: const Text("Plan History"),
|
||||
trailing: BarActions(
|
||||
store: store,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: child!,
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
75
lib/page/plan/history/widgets/bar_actions.dart
Normal file
75
lib/page/plan/history/widgets/bar_actions.dart
Normal file
@@ -0,0 +1,75 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:plan/widgets/ui_kit/popup/popup_action.dart';
|
||||
import 'package:remixicon/remixicon.dart';
|
||||
|
||||
import '../viewmodel/plan_list_store.dart';
|
||||
|
||||
class BarActions extends StatefulWidget {
|
||||
final PlanListStore store;
|
||||
const BarActions({super.key, required this.store});
|
||||
|
||||
@override
|
||||
State<BarActions> createState() => _BarActionsState();
|
||||
}
|
||||
|
||||
class _BarActionsState extends State<BarActions> {
|
||||
void _onSelected(String value) {
|
||||
switch (value) {
|
||||
case "Unarchived":
|
||||
widget.store.setPlanStatus(
|
||||
widget.store.planStatus.copyWith(
|
||||
unarchived: !widget.store.planStatus.unarchived,
|
||||
),
|
||||
);
|
||||
break;
|
||||
case "Archived":
|
||||
widget.store.setPlanStatus(
|
||||
widget.store.planStatus.copyWith(
|
||||
archived: !widget.store.planStatus.archived,
|
||||
),
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
PopupAction(
|
||||
onSelected: _onSelected,
|
||||
items: [
|
||||
PopupMenuItem(
|
||||
value: "Unarchived",
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text("Unarchived"),
|
||||
Visibility(
|
||||
visible: widget.store.planStatus.unarchived,
|
||||
child: Icon(RemixIcons.check_fill, size: 20),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: "Archived",
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text("Archived"),
|
||||
Visibility(
|
||||
visible: widget.store.planStatus.archived,
|
||||
child: Icon(RemixIcons.check_fill, size: 20),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
child: Icon(RemixIcons.more_fill),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
25
lib/page/plan/history/widgets/custom_indicator.dart
Normal file
25
lib/page/plan/history/widgets/custom_indicator.dart
Normal file
@@ -0,0 +1,25 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../viewmodel/plan_list_store.dart';
|
||||
|
||||
class CustomIndicator extends StatefulWidget {
|
||||
const CustomIndicator({super.key});
|
||||
|
||||
@override
|
||||
State<CustomIndicator> createState() => _CustomIndicatorState();
|
||||
}
|
||||
|
||||
class _CustomIndicatorState extends State<CustomIndicator> {
|
||||
Future<void> _onRefresh() async {
|
||||
PlanListStore store = context.read<PlanListStore>();
|
||||
await store.getPlanList();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CupertinoSliverRefreshControl(
|
||||
onRefresh: _onRefresh,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -3,86 +3,105 @@ import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:plan/api/dto/plan_item_dto.dart';
|
||||
import 'package:plan/api/endpoints/plan_api.dart';
|
||||
import 'package:plan/page/plan/history/viewmodel/plan_list_store.dart';
|
||||
import 'package:plan/router/config/route_paths.dart';
|
||||
import 'package:plan/utils/format.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:remixicon/remixicon.dart';
|
||||
|
||||
import '../../widgets/edit_desc_dialog.dart';
|
||||
import 'loading_box.dart';
|
||||
|
||||
class HistoryItem extends StatefulWidget {
|
||||
final PlanItemDto item;
|
||||
final bool showDelete;
|
||||
final Function(int) onDelete;
|
||||
final Function() onInit;
|
||||
|
||||
const HistoryItem({
|
||||
super.key,
|
||||
required this.item,
|
||||
this.showDelete = false,
|
||||
required this.onDelete,
|
||||
required this.onInit,
|
||||
});
|
||||
class HistoryList extends StatefulWidget {
|
||||
const HistoryList({super.key});
|
||||
|
||||
@override
|
||||
State<HistoryItem> createState() => _HistoryItemState();
|
||||
State<HistoryList> createState() => _HistoryListState();
|
||||
}
|
||||
|
||||
class _HistoryItemState extends State<HistoryItem> {
|
||||
late PlanItemDto _data;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_data = widget.item;
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant HistoryItem oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (oldWidget.item != widget.item) {
|
||||
setState(() {
|
||||
_data = widget.item;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class _HistoryListState extends State<HistoryList> {
|
||||
///跳转详情
|
||||
void _goDetail() async {
|
||||
await context.push(RoutePaths.planDetail(_data.id));
|
||||
widget.onInit();
|
||||
void _goDetail(PlanItemDto data) async {
|
||||
PlanListStore store = context.read<PlanListStore>();
|
||||
await context.push(RoutePaths.planDetail(data.id));
|
||||
store.getPlanList();
|
||||
}
|
||||
|
||||
///编辑摘要
|
||||
void _handEdit() {
|
||||
void _handEdit(PlanItemDto data) {
|
||||
context.pop();
|
||||
PlanListStore store = context.read<PlanListStore>();
|
||||
showEditDescDialog(
|
||||
context,
|
||||
value: _data.summary ?? "",
|
||||
value: data.summary ?? "",
|
||||
onConfirm: (value) async {
|
||||
setState(() {
|
||||
_data.summary = value;
|
||||
});
|
||||
await editPlanSummaryApi(_data.id!, value);
|
||||
data.summary = value;
|
||||
store.updateStep(data);
|
||||
await editPlanSummaryApi(data.id!, value);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
///删除计划
|
||||
void _handDelete() async {
|
||||
void _handDelete(PlanItemDto data) async {
|
||||
context.pop();
|
||||
widget.onDelete(_data.id!);
|
||||
await deletePlanApi(_data.id!);
|
||||
PlanListStore store = context.read<PlanListStore>();
|
||||
store.removeStep(data);
|
||||
await deletePlanApi(data.id!);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var progress = (_data.completedSteps! / _data.totalSteps!);
|
||||
return Consumer<PlanListStore>(
|
||||
builder: (context, store, _) {
|
||||
var record = store.planList.where((item) {
|
||||
var progress = (item.completedSteps! / item.totalSteps!);
|
||||
//不显示已完成
|
||||
if (!store.planStatus.archived && progress == 1) {
|
||||
return false;
|
||||
}
|
||||
//不显示未完成
|
||||
if (!store.planStatus.unarchived && progress < 1) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}).toList();
|
||||
|
||||
return LoadingBox(
|
||||
loading: store.isInit,
|
||||
isEmpty: record.isEmpty,
|
||||
child: CustomScrollView(
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
slivers: [
|
||||
SliverList.separated(
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
return _buildItem(
|
||||
item: record[index],
|
||||
);
|
||||
},
|
||||
separatorBuilder: (BuildContext context, int index) {
|
||||
return SizedBox(height: 15);
|
||||
},
|
||||
itemCount: record.length,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildItem({required PlanItemDto item}) {
|
||||
var progress = (item.completedSteps! / item.totalSteps!);
|
||||
return CupertinoContextMenu(
|
||||
enableHapticFeedback: true,
|
||||
actions: [
|
||||
// 编辑摘要
|
||||
CupertinoContextMenuAction(
|
||||
onPressed: _handEdit,
|
||||
onPressed: () {
|
||||
_handEdit(item);
|
||||
},
|
||||
child: _actionItem(
|
||||
"Edit Summary",
|
||||
CupertinoIcons.pencil,
|
||||
@@ -90,7 +109,9 @@ class _HistoryItemState extends State<HistoryItem> {
|
||||
),
|
||||
CupertinoContextMenuAction(
|
||||
isDestructiveAction: true,
|
||||
onPressed: _handDelete,
|
||||
onPressed: () {
|
||||
_handDelete(item);
|
||||
},
|
||||
child: _actionItem(
|
||||
"Delete Summary",
|
||||
CupertinoIcons.delete,
|
||||
@@ -98,7 +119,9 @@ class _HistoryItemState extends State<HistoryItem> {
|
||||
),
|
||||
],
|
||||
child: GestureDetector(
|
||||
onTap: _goDetail,
|
||||
onTap: () {
|
||||
_goDetail(item);
|
||||
},
|
||||
child: Container(
|
||||
width: 400,
|
||||
margin: EdgeInsets.symmetric(horizontal: 15),
|
||||
@@ -117,7 +140,7 @@ class _HistoryItemState extends State<HistoryItem> {
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(child: Text(_data.summary ?? "")),
|
||||
Expanded(child: Text(item.summary ?? "")),
|
||||
Visibility(
|
||||
visible: progress == 1,
|
||||
child: Container(
|
||||
@@ -140,7 +163,7 @@ class _HistoryItemState extends State<HistoryItem> {
|
||||
Container(
|
||||
margin: const EdgeInsets.only(bottom: 5, top: 5),
|
||||
child: Text(
|
||||
"${formatDateUS(_data.createdAt!, withTime: true)} · Coach ${_data.agentName ?? ""}",
|
||||
"${formatDateUS(item.createdAt!, withTime: true)} · Coach ${item.agentName ?? ""}",
|
||||
style: Theme.of(context).textTheme.labelSmall, // 小号文字
|
||||
),
|
||||
),
|
||||
@@ -154,7 +177,7 @@ class _HistoryItemState extends State<HistoryItem> {
|
||||
),
|
||||
),
|
||||
Text(
|
||||
"${_data.completedSteps}/${_data.totalSteps}",
|
||||
"${item.completedSteps}/${item.totalSteps}",
|
||||
style: Theme.of(context).textTheme.labelSmall,
|
||||
),
|
||||
],
|
||||
Reference in New Issue
Block a user