1.列表,筛选完成和未完成

2.详情,增加checkout
This commit is contained in:
zhutao
2025-09-24 10:22:35 +08:00
parent 9b3c08dabc
commit ca376d9393
19 changed files with 838 additions and 542 deletions

View File

@@ -1,5 +1,7 @@
import 'package:flutter/material.dart';
import 'package:plan/page/plan/detail/viewmodel/plan_detail_store.dart';
import 'package:plan/utils/common.dart';
import 'package:plan/utils/format.dart';
import 'package:provider/provider.dart';
class DoneStamp extends StatefulWidget {
@@ -38,6 +40,13 @@ class _DoneStampState extends State<DoneStamp> {
"Completed",
style: TextStyle(fontWeight: FontWeight.w700),
),
Visibility(
visible: getNotEmpty(store.planDetail.planEndTime) != null,
child: Text(
formatDateUS(store.planDetail.planEndTime!),
style: TextStyle(fontSize: 12),
),
),
],
),
),

View File

@@ -5,7 +5,7 @@ import 'package:plan/api/endpoints/plan_api.dart';
import 'package:plan/data/models/plan_acttion_type.dart';
import 'package:plan/page/plan/detail/viewmodel/plan_detail_store.dart';
import 'package:provider/provider.dart';
import 'package:remixicon/remixicon.dart';
import 'package:intl/intl.dart';
class FooterBtn extends StatefulWidget {
const FooterBtn({super.key});
@@ -30,6 +30,17 @@ class _FooterBtnState extends State<FooterBtn> {
return item.copyWith(stepStatus: allDone ? 0 : 2);
}).toList();
});
//如果是全部完成
if (!allDone) {
store.updatePlanDetail((dto) {
final now = DateTime.now();
final formatted = DateFormat('yyyy-MM-dd HH:mm:ss').format(now);
print(formatted);
dto.planEndTime = formatted;
});
}
//接口
editPlanStepApi(
store.planId,

View File

@@ -152,80 +152,105 @@ class PlanItem extends StatelessWidget {
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
if (!isEdit) {
onComplete(step);
}
},
child: Container(
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 10),
color: Colors.white,
child: DeleteRowItem(
showDelete: isEdit,
onDelete: () {
onDelete(step.id!);
return Selector<PlanDetailStore, String>(
selector: (_, store) => store.planContent,
builder: (context, planContent, _) {
return GestureDetector(
onTap: () {
if (!isEdit && planContent == "") {
onComplete(step);
}
},
builder: (_, animate) {
return [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
margin: EdgeInsets.only(bottom: 3),
child: Text(
step.stepContent ?? "",
style: stepTextStyle(context, Theme.of(context).textTheme.bodyMedium),
child: Container(
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 10),
color: Colors.white,
child: DeleteRowItem(
showDelete: isEdit,
onDelete: () {
onDelete(step.id!);
},
builder: (_, animate) {
return [
Visibility(
visible: !isEdit && planContent == "",
child: Transform.translate(
offset: Offset(0, -10),
child: Container(
width: 24,
height: 24,
margin: EdgeInsets.only(right: 10),
child: Checkbox(
value: step.stepStatus == 2,
onChanged: (value) {
onComplete(step);
},
),
),
),
AnimatedSwitcher(
duration: Duration(milliseconds: 300),
transitionBuilder: (child, animation) {
return FadeTransition(
opacity: animation,
child: SizeTransition(
sizeFactor: animation,
axis: Axis.vertical,
child: child,
),
);
},
child: getNotEmpty(step.stepExplain) == null
? SizedBox.shrink(key: ValueKey("empty"))
: Text(
step.stepExplain!,
style: stepTextStyle(
context,
Theme.of(context).textTheme.labelSmall,
),
key: ValueKey(step.stepExplain),
),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
margin: EdgeInsets.only(bottom: 3),
child: Text(
step.stepContent ?? "",
style: stepTextStyle(
context,
Theme.of(context).textTheme.bodyMedium,
),
),
],
),
),
SizeTransition(
axis: Axis.horizontal,
sizeFactor: animate,
child: GestureDetector(
onTap: () {
onEdit(step);
},
child: Container(
alignment: Alignment.center,
margin: EdgeInsets.only(left: 10),
child: Opacity(
opacity: 0.4,
child: Icon(RemixIcons.edit_box_line),
),
),
AnimatedSwitcher(
duration: Duration(milliseconds: 300),
transitionBuilder: (child, animation) {
return FadeTransition(
opacity: animation,
child: SizeTransition(
sizeFactor: animation,
axis: Axis.vertical,
child: child,
),
);
},
child: getNotEmpty(step.stepExplain) == null
? SizedBox.shrink(key: ValueKey("empty"))
: Text(
step.stepExplain!,
style: stepTextStyle(
context,
Theme.of(context).textTheme.labelSmall,
),
key: ValueKey(step.stepExplain),
),
),
],
),
),
),
),
];
},
),
),
SizeTransition(
axis: Axis.horizontal,
sizeFactor: animate,
child: GestureDetector(
onTap: () {
onEdit(step);
},
child: Container(
alignment: Alignment.center,
margin: EdgeInsets.only(left: 10),
child: Opacity(
opacity: 0.4,
child: Icon(RemixIcons.edit_box_line),
),
),
),
),
];
},
),
),
);
},
);
}

View File

@@ -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!,
);
},
),
);
}

View 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();
}
}

View 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),
),
],
);
}
}

View 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,
);
}
}

View File

@@ -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,
),
],