pile_nav_new/lib/pages/task/task_page.dart
2024-11-06 17:23:29 +08:00

323 lines
11 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'dart:developer';
import 'package:cpnav/main.dart';
import 'package:cpnav/pages/task/pile/pileGenerateCard/pile_generate.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:scence_map/controllers/controller.dart';
import 'package:scence_map/record_entity.dart';
import 'package:scence_map/scence_map.dart';
import '../pass_track/controller.dart';
import '../pass_track/view.dart';
import 'pile/pileGenerateCard/pile_point_table.dart';
import 'pile/pileNav/view.dart';
import 'taskcontroller.dart';
final ScenceMapController mapcontroller = Get.put(ScenceMapController());
class TaskManagePage extends StatelessWidget {
const TaskManagePage({super.key});
@override
Widget build(BuildContext context) {
final size = MediaQuery.of(context).size;
return OrientationBuilder(builder: ((context, orientation) {
return Center(
child: Container(
width: size.width * 0.8,
height: size.height * 0.18,
decoration: BoxDecoration(
border: Border.all(color: Colors.black),
borderRadius: BorderRadius.circular(10),
),
child: SingleChildScrollView(
child: Row(children: [
const SizedBox(width: 16),
const Icon(Icons.task,
size: 50, color: Color.fromARGB(164, 75, 73, 73)),
const SizedBox(width: 16),
SizedBox(
width: size.width * 0.4,
child: const Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(height: 5),
Text(
'任务',
style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
),
Row(children: [
Expanded(
child: TextField(
keyboardType: TextInputType.emailAddress,
decoration: InputDecoration(
labelText: "任务:",
hintText: "",
// prefixIcon: Icon(Icons.email),
border: InputBorder.none, //隐藏下划线
labelStyle: TextStyle(
fontSize: 16,
color: Color.fromARGB(164, 75, 73, 73)),
),
),
),
SizedBox(width: 5),
Expanded(
child: TextField(
keyboardType: TextInputType.emailAddress,
decoration: InputDecoration(
labelText: "桩点数:",
hintText: "0",
// prefixIcon: Icon(Icons.email),
border: InputBorder.none, //隐藏下划线
labelStyle: TextStyle(
fontSize: 16,
color: Color.fromARGB(164, 75, 73, 73)),
),
),
),
]),
],
),
),
// const SizedBox(width: 150),
Expanded(
child: Container(
alignment: Alignment.centerRight,
child:
Row(mainAxisAlignment: MainAxisAlignment.end, children: [
const Text(
'编辑',
style: TextStyle(
fontSize: 14, color: Color.fromARGB(164, 75, 73, 73)),
),
const SizedBox(width: 12),
InkWell(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const RealView()),
);
},
child: const Icon(Icons.arrow_forward_ios,
size: 30, color: Color.fromARGB(164, 75, 73, 73)),
)
])))
])),
));
}));
}
}
final controller = Get.put(PassTrackController("TEST", "pile_cm"));
final TaskController taskcontroller = Get.put(TaskController());
// class TaskPage extends StatelessWidget {
class TaskPage extends StatefulWidget {
const TaskPage({super.key});
@override
TaskPageState createState() => TaskPageState();
}
class TaskPageState extends State<TaskPage> {
late StepDialogManager _showStepDialog;
@override
void initState() {
super.initState();
_showStepDialog = StepDialogManager(context);
}
@override
Widget build(BuildContext context) {
final size = MediaQuery.of(context).size;
// final mediaQueryData = MediaQueryData.fromView(View.of(context)); //获取当前屏幕信息
// final orientation = mediaQueryData.orientation; //获得设备方向
// bool isPortrait = Orientation.portrait == orientation ? true : false;
return Scaffold(
endDrawer: Drawer(
width: size.width * .5,
child: PilePointTable(
pilePoints: mapcontroller.pilePoints,
onUpdate: (updatedPilePoints) {
// 这里可以处理更新后的桩点列表
log("生成桩点$updatedPilePoints,");
for (var updatedPilePoint in updatedPilePoints) {
// 查找 recordList 中对应的 RecordEntity
RecordEntity? recordEntity =
mapController.recordList.firstWhere(
(record) => record.id == updatedPilePoint.id,
orElse: () => RecordEntity(
id: -1, // 使用一个无效的 id 表示未找到
tid: 0,
startTime: DateTime.now(),
endTime: DateTime.now(),
pileId: 0,
name: '',
times: 0,
lat: 0.0,
lng: 0.0,
x: 0.0,
y: 0.0,
h: 0.0,
totalFlow: 0.0,
titlXavg: 0.0,
titlYavg: 0.0,
current1Avg: 0.0,
current2Avg: 0.0,
quality: 0,
reason: '',
remark: '',
depth: 0,
speed: 0.0,
),
);
if (recordEntity.id != -1) {
// 更新 RecordEntity 的属性
recordEntity.x = updatedPilePoint.x;
recordEntity.y = updatedPilePoint.y;
// 其他属性的更新
} else {
// 如果找不到对应的 RecordEntity则添加新的
recordEntity = RecordEntity(
id: updatedPilePoint.id,
tid: 0,
startTime: DateTime.now(),
endTime: DateTime.now(),
pileId: 0,
name: '',
times: 0,
lat: 0.0,
lng: 0.0,
x: updatedPilePoint.x,
y: updatedPilePoint.y,
h: 0.0,
totalFlow: 0.0,
titlXavg: 0.0,
titlYavg: 0.0,
current1Avg: 0.0,
current2Avg: 0.0,
quality: 0,
reason: '',
remark: '',
depth: 0,
speed: 0.0,
);
mapController.recordList.add(recordEntity);
}
}
},
),
),
appBar: AppBar(
title: const Text('任务页面'),
actions: [
UnconstrainedBox(
child: SizedBox(
height: 30,
child: Builder(
builder: (context) => Obx(
() => InkWell(
child: Icon(
Icons.close,
size: 35,
color: appcontroller.isDarkMode.value
? Colors.white70
: const Color.fromARGB(200, 29, 28, 28),
),
onTap: () => Scaffold.of(context).openEndDrawer(),
),
),
),
),
),
UnconstrainedBox(
child: SizedBox(
height: 30,
child: InkWell(
child: Obx(
() => Icon(
Icons.settings_outlined,
size: 35,
color: appcontroller.isDarkMode.value
? Colors.white70
: const Color.fromARGB(200, 29, 28, 28),
),
),
onTap: () {
pilecontroller.isPileCardVisible.value = true;
if (!taskcontroller.isDialogShown[0]) {
_showStepDialog.showStepDialog(0);
taskcontroller.isDialogShown[0] = true;
}
},
),
),
),
],
),
body: Stack(
children: [
ScenceMapView(
onUpdate: (Offset center, double scale, double rotation) {
log("center:$center scale:$scale rotation:$rotation");
},
forGroundPainter: appcontroller.currentIndex.value == 1
? BorderPainter(controller)
: null,
onUpdatePilePoint: (RecordEntity? selectedPilePoint, double scale,
double rotation) {
log(
"selectedPilePoint:$selectedPilePoint scale:$scale rotation:$rotation");
},
children: const [],
),
// ),
if (pilecontroller.isPileCardVisible.value)
const PileGenerateCard(),
],
));
}
}
//对话框
class StepDialogManager {
final BuildContext context;
final List<String> _stepTexts = [
'点击屏幕即可确定桩点中心。',
'这是步骤 2 的提示对话框。',
'这是步骤 3 的提示对话框。',
'点击方向设置按钮和输入宽度值可设置桩点范围。',
'手指在屏幕上拖动可确定桩点范围'
];
StepDialogManager(this.context);
void showStepDialog(int step) {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: const Text('步骤提示'),
content: Text(_stepTexts[step]),
actions: <Widget>[
TextButton(
child: const Text('确定'),
onPressed: () {
Navigator.of(context).pop();
for (int i = 0; i < taskcontroller.isDialogShown.length; i++) {
taskcontroller.isDialogShown[i] = false;
}
},
),
],
);
},
);
}
}