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

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