pile_nav_new/lib/pages/task/task_page.dart
2024-09-05 12:06:03 +08:00

316 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 'package:cpnav/main.dart';
import 'package:cpnav/pages/task/pile/pileGenerateCard/pileGenerate.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:get/get_connect/http/src/utils/utils.dart';
import 'package:scence_map/controllers/controller.dart';
import 'package:scence_map/record_entity.dart';
import 'package:scence_map/scence_map.dart';
import '../aim_point/aimpoint_page.dart';
import '../pass_track/controller.dart';
import '../pass_track/view.dart';
import 'pile/pileGenerateCard/pilePointTable.dart';
import 'pile/pileNav/view.dart';
import 'taskcontroller.dart';
final ScenceMapController mapcontroller = Get.put(ScenceMapController());
class TaskManagePage extends StatelessWidget {
@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: [
SizedBox(width: 16),
Icon(Icons.task, size: 50, color: Color.fromARGB(164, 75, 73, 73)),
SizedBox(width: 16),
Container(
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)),
),
),
),
]),
],
),
),
SizedBox(width: 150),
Container(
alignment: Alignment.centerLeft,
child: Container(
child: Row(children: [
const Text(
'编辑',
style: TextStyle(
fontSize: 14, color: Color.fromARGB(164, 75, 73, 73)),
),
SizedBox(width: 12),
InkWell(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => 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 {
@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;
MediaQueryData mediaQueryData =
MediaQueryData.fromView(WidgetsBinding.instance.window); //获取当前屏幕信息
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) {
// 这里可以处理更新后的桩点列表
print("生成桩点$updatedPilePoints,");
updatedPilePoints.forEach((updatedPilePoint) {
// 查找 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: 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(
children: [],
onUpdate: (Offset center, double scale, double rotation) {
print("center:$center scale:$scale rotation:$rotation");
},
forGroundPainter: appcontroller.currentIndex.value == 1
? BorderPainter(controller)
: null,
onUpdatePilePoint: (RecordEntity? selectedPilePoint, double scale,
double rotation) {
print(
"selectedPilePoint:$selectedPilePoint scale:$scale rotation:$rotation");
},
),
// ),
if (pilecontroller.isPileCardVisible.value) 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: Text('步骤提示'),
content: Text(_stepTexts[step]),
actions: <Widget>[
TextButton(
child: Text('确定'),
onPressed: () {
Navigator.of(context).pop();
for (int i = 0; i < taskcontroller.isDialogShown.length; i++) {
taskcontroller.isDialogShown[i] = false;
}
},
),
],
);
},
);
}
}