80 lines
2.2 KiB
Dart
80 lines
2.2 KiB
Dart
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),
|
||
),
|
||
),
|
||
],
|
||
);
|
||
}
|
||
}
|