文案ok
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:plan/api/endpoints/plan_api.dart';
|
||||
import 'package:plan/widgets/ui_kit/popup/popup_action.dart';
|
||||
import 'package:remixicon/remixicon.dart';
|
||||
@@ -29,7 +28,7 @@ class _BarActionsState extends State<BarActions> {
|
||||
widget.store.updatePlanDetail((dto) {
|
||||
dto.summary = value;
|
||||
});
|
||||
await editPlanSummaryApi(int.parse(widget.store.planId), value);
|
||||
await editPlanSummaryApi(widget.store.planId, value);
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -64,11 +63,11 @@ class _BarActionsState extends State<BarActions> {
|
||||
items: [
|
||||
PopupMenuItem(
|
||||
value: 'edit_step',
|
||||
child: Text("编辑步骤"),
|
||||
child: Text("Edit Steps"),
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: 'edit_desc',
|
||||
child: Text("编辑摘要"),
|
||||
child: Text("Edit Summary"),
|
||||
),
|
||||
],
|
||||
child: Icon(RemixIcons.more_fill),
|
||||
135
lib/page/plan/detail/other/edit_popup.dart
Normal file
135
lib/page/plan/detail/other/edit_popup.dart
Normal file
@@ -0,0 +1,135 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:plan/api/dto/plan_detail_dto.dart';
|
||||
|
||||
class EditPopup extends StatefulWidget {
|
||||
final PlanStepDto step;
|
||||
final Function(PlanStepDto) onEdit;
|
||||
|
||||
const EditPopup({super.key, required this.step, required this.onEdit});
|
||||
|
||||
@override
|
||||
State<EditPopup> createState() => _EditPopupState();
|
||||
}
|
||||
|
||||
class _EditPopupState extends State<EditPopup> {
|
||||
///输入框
|
||||
final TextEditingController _titleController = TextEditingController();
|
||||
final TextEditingController _descriptionController = TextEditingController();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_titleController.text = widget.step.stepContent ?? "";
|
||||
_descriptionController.text = widget.step.stepExplain ?? "";
|
||||
|
||||
// 监听任何一次输入
|
||||
_titleController.addListener(_updateSaveButton);
|
||||
_descriptionController.addListener(_updateSaveButton);
|
||||
}
|
||||
|
||||
///是否允许保存
|
||||
get isSave => _titleController.text.isNotEmpty && _descriptionController.text.isNotEmpty;
|
||||
|
||||
void _updateSaveButton() => setState(() {});
|
||||
|
||||
///保存
|
||||
void _handSave() {
|
||||
//更新数据
|
||||
var step = widget.step.copyWith(
|
||||
stepContent: _titleController.text,
|
||||
stepExplain: _descriptionController.text,
|
||||
);
|
||||
|
||||
widget.onEdit(step);
|
||||
context.pop();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(top: 40),
|
||||
child: Container(
|
||||
clipBehavior: Clip.hardEdge,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.only(
|
||||
topLeft: Radius.circular(10),
|
||||
topRight: Radius.circular(10),
|
||||
),
|
||||
),
|
||||
child: CupertinoPageScaffold(
|
||||
backgroundColor: Theme.of(context).colorScheme.surfaceContainer,
|
||||
navigationBar: CupertinoNavigationBar(
|
||||
middle: Text("Edit Steps"),
|
||||
leading: CupertinoButton(
|
||||
padding: EdgeInsets.zero,
|
||||
onPressed: () {
|
||||
context.pop();
|
||||
},
|
||||
child: Text("Cancel", style: TextStyle(color: CupertinoColors.black)),
|
||||
),
|
||||
trailing: CupertinoButton(
|
||||
padding: EdgeInsets.zero,
|
||||
|
||||
onPressed: isSave ? _handSave : null,
|
||||
child: Text("Save"),
|
||||
),
|
||||
),
|
||||
child: SafeArea(
|
||||
child: ListView(
|
||||
padding: EdgeInsets.all(15),
|
||||
children: [
|
||||
_smallTitle("STEP DETAILS"),
|
||||
Container(
|
||||
padding: EdgeInsets.all(15),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
_input(_titleController, "Task"),
|
||||
Divider(),
|
||||
_input(_descriptionController, "Description"),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _smallTitle(String title) {
|
||||
return Container(
|
||||
margin: EdgeInsets.only(bottom: 5),
|
||||
padding: EdgeInsets.only(left: 10),
|
||||
child: Text(
|
||||
title,
|
||||
style: Theme.of(context).textTheme.labelSmall?.copyWith(
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
///输入框
|
||||
Widget _input(TextEditingController controller, String hint) {
|
||||
return TextField(
|
||||
maxLines: null,
|
||||
minLines: 3,
|
||||
// 允许无限换行
|
||||
keyboardType: TextInputType.multiline,
|
||||
controller: controller,
|
||||
style: TextStyle(fontSize: 16),
|
||||
decoration: InputDecoration(
|
||||
hintText: hint,
|
||||
border: InputBorder.none,
|
||||
isCollapsed: true,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:plan/page/plan/detail/navigation/bar_actions.dart';
|
||||
import 'package:plan/page/plan/detail/viewmodel/plan_detail_store.dart';
|
||||
import 'package:plan/theme/decorations/app_shadows.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'other/bar_actions.dart';
|
||||
import 'widgets/avatar_card.dart';
|
||||
import 'widgets/coach_message.dart';
|
||||
import 'widgets/plan_list.dart';
|
||||
@@ -12,7 +12,7 @@ import 'widgets/scroll_box.dart';
|
||||
import 'widgets/suggested.dart';
|
||||
|
||||
class PlanDetailPage extends StatefulWidget {
|
||||
final String? id;
|
||||
final int? id;
|
||||
final String? planName;
|
||||
|
||||
const PlanDetailPage({
|
||||
@@ -35,7 +35,7 @@ class _PlanDetailPageState extends State<PlanDetailPage> {
|
||||
void initState() {
|
||||
super.initState();
|
||||
store = PlanDetailStore(
|
||||
planId: widget.id.toString(),
|
||||
planId: widget.id ?? 0,
|
||||
planContent: widget.planName ?? "",
|
||||
scrollController: scrollController,
|
||||
);
|
||||
|
||||
@@ -8,11 +8,11 @@ class PlanDetailStore extends ChangeNotifier {
|
||||
///构造函数
|
||||
PlanDetailStore({
|
||||
this.planContent = "",
|
||||
this.planId = "",
|
||||
required this.planId,
|
||||
required this.scrollController,
|
||||
}) {
|
||||
//如果没有id进行初始化
|
||||
if (planId == "0") {
|
||||
if (planId == 0) {
|
||||
createPlan();
|
||||
} else {
|
||||
//获取详情
|
||||
@@ -37,10 +37,10 @@ class PlanDetailStore extends ChangeNotifier {
|
||||
String planContent = "";
|
||||
|
||||
///计划id
|
||||
String planId = "";
|
||||
int planId;
|
||||
|
||||
///计划详情
|
||||
PlanDetailDto planDetail = PlanDetailDto(summary: "计划详情");
|
||||
PlanDetailDto planDetail = PlanDetailDto(summary: "Plan Details");
|
||||
|
||||
///是否正在编辑
|
||||
bool isEdit = false;
|
||||
@@ -57,7 +57,7 @@ class PlanDetailStore extends ChangeNotifier {
|
||||
///创建计划
|
||||
void createPlan() async {
|
||||
var id = await initPlanApi(planContent, 1);
|
||||
planId = id.toString();
|
||||
planId = id;
|
||||
|
||||
///生成摘要---------------------------
|
||||
String summary = "";
|
||||
@@ -162,7 +162,8 @@ class PlanDetailStore extends ChangeNotifier {
|
||||
steps: planDetail.stepsList,
|
||||
suggestions: planDetail.suggestionsList,
|
||||
);
|
||||
EasyLoading.showToast("计划创建成功");
|
||||
await getPlanDetail();
|
||||
EasyLoading.showToast("Plan created!");
|
||||
}
|
||||
|
||||
///获取详情
|
||||
@@ -176,4 +177,13 @@ class PlanDetailStore extends ChangeNotifier {
|
||||
updater(planDetail);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
///更新步骤
|
||||
void updateStep(PlanStepDto newStep) {
|
||||
final int index = planDetail.stepsList.indexWhere((e) => e.id == newStep.id);
|
||||
if (index != -1) {
|
||||
planDetail.stepsList[index] = newStep; // 引用变了 → 框架感知
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,6 +94,7 @@ class _AvatarCardState extends State<AvatarCard> with SingleTickerProviderStateM
|
||||
child: Stack(
|
||||
children: [
|
||||
Container(
|
||||
width: double.infinity,
|
||||
padding: EdgeInsets.all(4),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(3),
|
||||
@@ -119,7 +120,7 @@ class _AvatarCardState extends State<AvatarCard> with SingleTickerProviderStateM
|
||||
child: Stack(
|
||||
alignment: Alignment.bottomCenter,
|
||||
children: [
|
||||
Image.asset("assets/image/xiaozhi.png", height: 100),
|
||||
Image.asset("assets/image/kbn.png", height: 100),
|
||||
Positioned(
|
||||
top: 20,
|
||||
child: Transform.translate(
|
||||
|
||||
@@ -21,7 +21,7 @@ class _CoachMessageState extends State<CoachMessage> {
|
||||
child: Column(
|
||||
children: [
|
||||
Text(
|
||||
"你的教练正在拆分",
|
||||
"Organizing your plan…",
|
||||
style: Theme.of(context).textTheme.bodyMedium,
|
||||
),
|
||||
Text(
|
||||
|
||||
@@ -10,6 +10,8 @@ import 'package:plan/widgets/business/delete_row_item.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:remixicon/remixicon.dart';
|
||||
|
||||
import '../other/edit_popup.dart';
|
||||
|
||||
class PlanList extends StatefulWidget {
|
||||
const PlanList({super.key});
|
||||
|
||||
@@ -30,7 +32,7 @@ class _PlanListState extends State<PlanList> {
|
||||
dto.stepsList = dto.stepsList.where((element) => element.id != id).toList();
|
||||
});
|
||||
await editPlanStepApi(
|
||||
int.parse(store.planId),
|
||||
store.planId,
|
||||
act: PlanActionType.delete,
|
||||
stepId: id,
|
||||
);
|
||||
@@ -42,37 +44,56 @@ class _PlanListState extends State<PlanList> {
|
||||
store.updatePlanDetail((dto) {
|
||||
dto.stepsList = list;
|
||||
});
|
||||
await editPlanStepOrderApi(int.parse(store.planId), list);
|
||||
await editPlanStepOrderApi(store.planId, list);
|
||||
}
|
||||
|
||||
///确认完成或者取消
|
||||
void _handComplete(int id) async {
|
||||
void _handComplete(PlanStepDto newStep) async {
|
||||
HapticFeedback.vibrate();
|
||||
var store = context.read<PlanDetailStore>();
|
||||
newStep.stepStatus = newStep.stepStatus == 2 ? 0 : 2;
|
||||
//更新数据
|
||||
store.updateStep(newStep);
|
||||
//接口更新
|
||||
editPlanStepApi(
|
||||
store.planId,
|
||||
act: PlanActionType.complete,
|
||||
stepId: newStep.id,
|
||||
);
|
||||
}
|
||||
|
||||
store.updatePlanDetail((dto) {
|
||||
dto.stepsList = dto.stepsList.map((step) {
|
||||
if (step.id == id) {
|
||||
// 只更新匹配的项
|
||||
step.stepStatus = step.stepStatus == 2 ? 0 : 2;
|
||||
editPlanStepApi(
|
||||
int.parse(store.planId),
|
||||
act: PlanActionType.complete,
|
||||
stepId: id,
|
||||
);
|
||||
}
|
||||
return step;
|
||||
}).toList();
|
||||
});
|
||||
///打开编辑
|
||||
void _handEditDialog(PlanStepDto step) {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
backgroundColor: Colors.transparent,
|
||||
builder: (_) {
|
||||
return EditPopup(
|
||||
step: step,
|
||||
onEdit: (newStep) {
|
||||
var store = context.read<PlanDetailStore>();
|
||||
store.updateStep(newStep);
|
||||
// 接口
|
||||
editPlanStepApi(
|
||||
store.planId,
|
||||
act: PlanActionType.edit,
|
||||
stepId: newStep.id,
|
||||
content: newStep.stepContent,
|
||||
explain: newStep.stepExplain,
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final isEdit = context.select<PlanDetailStore, bool>((s) => s.isEdit);
|
||||
return Selector<PlanDetailStore, List<String>>(
|
||||
selector: (_, store) => store.planDetail.stepsList
|
||||
.map((e) => '${e.id}_${e.stepExplain}_${e.stepStatus}')
|
||||
.toList(),
|
||||
selector: (_, store) =>
|
||||
store.planDetail.stepsList.map((e) => e.toJson().toString()).toList(),
|
||||
builder: (context, list, _) {
|
||||
final list = context.read<PlanDetailStore>().planDetail.stepsList;
|
||||
return AnimatedReorderableListView(
|
||||
@@ -87,6 +108,7 @@ class _PlanListState extends State<PlanList> {
|
||||
isEdit: isEdit,
|
||||
onDelete: _handDelete,
|
||||
onComplete: _handComplete,
|
||||
onEdit: _handEditDialog,
|
||||
);
|
||||
},
|
||||
enterTransition: [SlideInDown()],
|
||||
@@ -116,7 +138,8 @@ class PlanItem extends StatelessWidget {
|
||||
final PlanStepDto step;
|
||||
final bool isEdit;
|
||||
final Function(int) onDelete;
|
||||
final Function(int) onComplete;
|
||||
final Function(PlanStepDto) onComplete;
|
||||
final Function(PlanStepDto) onEdit;
|
||||
|
||||
const PlanItem({
|
||||
super.key,
|
||||
@@ -124,6 +147,7 @@ class PlanItem extends StatelessWidget {
|
||||
this.isEdit = false,
|
||||
required this.onDelete,
|
||||
required this.onComplete,
|
||||
required this.onEdit,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -131,7 +155,7 @@ class PlanItem extends StatelessWidget {
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
if (!isEdit) {
|
||||
onComplete(step.id!);
|
||||
onComplete(step);
|
||||
}
|
||||
},
|
||||
child: Container(
|
||||
@@ -184,12 +208,17 @@ class PlanItem extends StatelessWidget {
|
||||
SizeTransition(
|
||||
axis: Axis.horizontal,
|
||||
sizeFactor: animate,
|
||||
child: Container(
|
||||
alignment: Alignment.center,
|
||||
margin: EdgeInsets.only(left: 10),
|
||||
child: Opacity(
|
||||
opacity: 0.4,
|
||||
child: Icon(RemixIcons.menu_line),
|
||||
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),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -37,7 +37,7 @@ class SuggestedTitle extends StatelessWidget {
|
||||
color: Theme.of(context).colorScheme.surfaceContainerHigh,
|
||||
),
|
||||
Text(
|
||||
"额外建议",
|
||||
"Additional Suggestions",
|
||||
style: Theme.of(context).textTheme.titleSmall,
|
||||
),
|
||||
Container(
|
||||
|
||||
Reference in New Issue
Block a user