文案ok
This commit is contained in:
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