文案ok
This commit is contained in:
79
lib/page/plan/detail/other/bar_actions.dart
Normal file
79
lib/page/plan/detail/other/bar_actions.dart
Normal file
@@ -0,0 +1,79 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:plan/api/endpoints/plan_api.dart';
|
||||
import 'package:plan/widgets/ui_kit/popup/popup_action.dart';
|
||||
import 'package:remixicon/remixicon.dart';
|
||||
|
||||
import '../../widgets/edit_desc_dialog.dart';
|
||||
import '../viewmodel/plan_detail_store.dart';
|
||||
|
||||
class BarActions extends StatefulWidget {
|
||||
final PlanDetailStore store;
|
||||
|
||||
const BarActions({super.key, required this.store});
|
||||
|
||||
@override
|
||||
State<BarActions> createState() => _BarActionsState();
|
||||
}
|
||||
|
||||
class _BarActionsState extends State<BarActions> {
|
||||
///popup菜单
|
||||
void _onPopupActionSelected(String value) {
|
||||
if (value == 'edit_step') {
|
||||
widget.store.setEdit(true);
|
||||
} else if (value == 'edit_desc') {
|
||||
showEditDescDialog(
|
||||
context,
|
||||
value: widget.store.planDetail.summary ?? "",
|
||||
onConfirm: (value) async {
|
||||
widget.store.updatePlanDetail((dto) {
|
||||
dto.summary = value;
|
||||
});
|
||||
await editPlanSummaryApi(widget.store.planId, value);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
///取消编辑
|
||||
void _cancelEdit() {
|
||||
widget.store.setEdit(false);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
mainAxisSize: MainAxisSize.min, // 关键:Row 只占实际内容宽度
|
||||
children: [
|
||||
AnimatedSwitcher(
|
||||
duration: Duration(milliseconds: 300),
|
||||
transitionBuilder: (child, animation) {
|
||||
// 仅使用渐变动画
|
||||
return FadeTransition(
|
||||
opacity: animation,
|
||||
child: child,
|
||||
);
|
||||
},
|
||||
child: widget.store.isEdit
|
||||
? InkWell(
|
||||
onTap: _cancelEdit,
|
||||
child: Icon(RemixIcons.check_fill),
|
||||
)
|
||||
: PopupAction(
|
||||
onSelected: _onPopupActionSelected,
|
||||
items: [
|
||||
PopupMenuItem(
|
||||
value: 'edit_step',
|
||||
child: Text("Edit Steps"),
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: 'edit_desc',
|
||||
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,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user