pile_nav_new/lib/pages/task/info.dart
2024-11-15 17:42:52 +08:00

218 lines
8.2 KiB
Dart

import 'package:cpnav/main.dart';
import 'package:cpnav/pages/task/model.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'pile/pileNav/view.dart';
import 'taskcontroller.dart';
// ignore: must_be_immutable
class TaskItemPage extends GetWidget<TaskController> {
TaskItem taskInfo;
TaskItemPage({super.key, required this.taskInfo});
toTaskView(context, TaskItem taskInfo) {
controller.currentask.value = taskInfo;
Navigator.push(
context,
MaterialPageRoute(builder: (context) => const TaskView()),
);
}
@override
Widget build(BuildContext context) {
return Container(
// width: size.width * 0.8,
height: 85,
decoration: BoxDecoration(
border: Border.all(color: Colors.black),
borderRadius: BorderRadius.circular(10),
),
margin: const EdgeInsets.only(bottom: 5),
clipBehavior: Clip.hardEdge,
child: Obx(() {
Color color = controller.currentask.value.utc == taskInfo.utc
? Colors.green
: const Color.fromARGB(164, 75, 73, 73);
IconData icon = controller.currentask.value.utc == taskInfo.utc
? Icons.task_rounded
: Icons.task_outlined;
if (controller.currentask.value.utc == taskInfo.utc) {
taskInfo = controller.currentask.value;
}
int workTotal = taskInfo.workTotal;
int listLength = taskInfo.list.length;
TextEditingController taskController =
TextEditingController(text: workTotal.toString());
TextEditingController totalController =
TextEditingController(text: listLength.toString());
Size size = MediaQuery.of(context).size;
return Stack(
children: [
Row(children: [
const SizedBox(width: 16),
IconButton(
onPressed: () {
controller.currentask.value = taskInfo;
appcontroller.currentIndex.value = 1;
},
icon: Icon(icon, size: 50, color: color)),
const SizedBox(width: 16),
SizedBox(
width: size.width * 0.4,
child: InkWell(
onTap: () {
controller.currentask.value = taskInfo;
appcontroller.currentIndex.value = 1;
// toTaskView(context);
},
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// SizedBox(height: 5),
Text(
taskInfo.name,
style: const TextStyle(
fontSize: 24, fontWeight: FontWeight.bold),
),
Row(children: [
Expanded(
child: TextField(
readOnly: true,
keyboardType: TextInputType.emailAddress,
controller: taskController,
decoration: const InputDecoration(
prefixText: '完成数量:',
border: InputBorder.none,
labelStyle: TextStyle(
fontSize: 16,
color: Color.fromARGB(164, 75, 73, 73)),
),
),
),
const SizedBox(width: 5),
Expanded(
child: TextField(
readOnly: true,
controller: totalController,
keyboardType: TextInputType.emailAddress,
decoration: const InputDecoration(
prefixText: "桩点数:",
hintText: "0",
// prefixIcon: Icon(Icons.email),
border: InputBorder.none, //隐藏下划线
labelStyle: TextStyle(
fontSize: 16,
color: Color.fromARGB(164, 75, 73, 73)),
),
),
),
]),
],
)),
),
// const SizedBox(width: 150),
InkWell(
onTap: () {
toTaskView(context, taskInfo);
},
child: Container(
width: size.width * .3,
height: 80,
alignment: Alignment.center,
child: const Text(
"编辑桩点 >>>",
style: TextStyle(
fontSize: 14,
color: Color.fromARGB(164, 75, 73, 73)),
)),
),
InkWell(
onTap: () => editDialog(context, taskInfo),
child: Container(
width: size.width * .1,
height: 80,
alignment: Alignment.center,
child: const Text(
'编辑名称',
style: TextStyle(
fontSize: 14, color: Color.fromARGB(164, 75, 73, 73)),
),
),
),
]),
Positioned(
top: -3, // 调整文本的位置
left: -37, // 调整文本的位置
child: Transform.rotate(
angle: -40 * 3.14159 / 180, // 旋转 45°
child: Container(
width: 100,
padding: const EdgeInsets.all(4), // 添加一些内边距
color: Colors.blue,
alignment: Alignment.bottomCenter,
// 背景颜色
child: Text(
taskInfo.originLabel,
textAlign: TextAlign.center,
style: const TextStyle(
fontSize: 16, color: Colors.white), // 设置字体颜色为白色
),
),
),
),
],
);
}));
}
editDialog(context, TaskItem info) {
TextEditingController taskController =
TextEditingController(text: info.name.toString());
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: const Text("新增任务"),
content: SizedBox(
height: 100,
child: Column(
children: [
TextField(
keyboardType: TextInputType.emailAddress,
controller: taskController,
decoration: const InputDecoration(
hintText: '任务名称',
prefixText: '任务名称:',
border: InputBorder.none,
labelStyle: TextStyle(
fontSize: 16, color: Color.fromARGB(164, 75, 73, 73)),
),
)
],
),
),
actions: <Widget>[
TextButton(
onPressed: () {
Navigator.of(context).pop(); // 关闭弹窗
},
child: const Text("取消"),
),
TextButton(
onPressed: () async {
info.name = taskController.text.trim();
await controller.editTask(info);
// ignore: use_build_context_synchronously
Navigator.of(context).pop();
controller.updateCount++;
},
child: const Text("确定"),
),
],
);
},
);
}
}