218 lines
7.1 KiB
Dart
218 lines
7.1 KiB
Dart
import 'dart:math';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:scence_map/controllers/controller.dart';
|
|
import 'package:scence_map/controllers/plumController.dart';
|
|
import 'package:scence_map/record_entity.dart';
|
|
|
|
import 'package:scence_map/scence_map.dart';
|
|
import 'package:get/get.dart';
|
|
|
|
import '../../../models/pilePoint/hyrecorditem.dart';
|
|
import '../../pass_track/view.dart';
|
|
import '../../task/task_page.dart';
|
|
import '../pileGenerateCard/pileGenerate.dart';
|
|
import 'draw_pile.dart';
|
|
|
|
class RealView extends StatefulWidget {
|
|
const RealView({super.key});
|
|
|
|
@override
|
|
State<RealView> createState() => _RealViewState();
|
|
}
|
|
|
|
class _RealViewState extends State<RealView> {
|
|
final ScenceMapController scenceMapController =
|
|
Get.put(ScenceMapController());
|
|
final controller = Get.find<PlumDataController>();
|
|
@override
|
|
void dispose() {
|
|
super.dispose();
|
|
}
|
|
|
|
bool isInit = false;
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
// scenceMapController.disableMove.value = false;
|
|
scenceMapController.update();
|
|
isInit = true;
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final isDarkMode = Theme.of(context).brightness == Brightness.dark;
|
|
double diagonal = scenceMapController.diagonal;
|
|
double mapWidth = scenceMapController.width;
|
|
double mapHeight = scenceMapController.height;
|
|
Offset scOffset =
|
|
Offset(mapWidth / 2 - diagonal / 2, mapHeight / 2 - diagonal / 2);
|
|
onTapDown(TapDownDetails details) {
|
|
isInit = false;
|
|
if (controller.checkValue.value == "checkPile") {
|
|
// controller.centerOffset.value = details.localPosition;
|
|
Offset sc2xy = scenceMapController.screen2xy0(details.localPosition);
|
|
controller.centerXY.value = sc2xy;
|
|
|
|
RecordEntity? checkPoint =
|
|
scenceMapController.pointInfo(controller.centerXY.value);
|
|
|
|
if (checkPoint != null) {
|
|
controller.isPileId.value = true;
|
|
// controller.checkName.value = checkPoint.tpId.toString();
|
|
} else {
|
|
controller.isPileId.value = false;
|
|
controller.checkName.value = "未找到";
|
|
}
|
|
}
|
|
}
|
|
|
|
onScaleStart(ScaleStartDetails details) {
|
|
if (controller.checkValue.value != "checkPile") {
|
|
controller.linePointOffset.value = details.localFocalPoint;
|
|
}
|
|
// controller.shouldPaint.value = true;
|
|
}
|
|
|
|
onScaleUpdate(ScaleUpdateDetails details) {
|
|
controller.isUp.value = false;
|
|
// controller.shouldPaint.value = true;
|
|
if (controller.checkValue.value != "checkPile") {
|
|
if (controller.linePointOffset.value != details.localFocalPoint) {
|
|
controller.linePointXY.value =
|
|
scenceMapController.screen2xy0(details.localFocalPoint);
|
|
|
|
controller.updateLinePoint(details.localFocalPoint);
|
|
}
|
|
}
|
|
controller.isUp.value = true;
|
|
}
|
|
|
|
onScaleEnd(ScaleEndDetails details) {
|
|
double deg = (atan2(
|
|
controller.linePointOffset.value.dy -
|
|
controller.centerOffset.value.dy,
|
|
controller.linePointOffset.value.dx -
|
|
controller.centerOffset.value.dx) *
|
|
180 /
|
|
pi)
|
|
.roundToDouble();
|
|
controller.direction.value = deg + 90;
|
|
controller.angle.value =
|
|
((controller.direction.value * pi / 180) * 100).round() / 100;
|
|
|
|
controller.isUp.value = true;
|
|
}
|
|
|
|
// 中间
|
|
var center = Obx(() {
|
|
// 桩点生成
|
|
if (!controller.isGenerate.value) {
|
|
return const Text("");
|
|
}
|
|
|
|
return Positioned(
|
|
width: scenceMapController.diagonal,
|
|
height: scenceMapController.diagonal,
|
|
top: scOffset.dy,
|
|
left: scOffset.dx,
|
|
child: GestureDetector(
|
|
onTapDown: (TapDownDetails details) => onTapDown(details),
|
|
onScaleStart: (ScaleStartDetails details) => onScaleStart(details),
|
|
onScaleUpdate: (ScaleUpdateDetails details) =>
|
|
onScaleUpdate(details),
|
|
onScaleEnd: (ScaleEndDetails details) => onScaleEnd(details),
|
|
child: Container(
|
|
clipBehavior: Clip.hardEdge,
|
|
decoration: BoxDecoration(
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: Colors.black.withOpacity(0.2),
|
|
blurRadius: 8,
|
|
offset: const Offset(0, 4),
|
|
),
|
|
],
|
|
),
|
|
child: Obx(() {
|
|
////必须写 因为 需要监听 -- 的值发生变化 刷新
|
|
|
|
controller.linePointOffset.value;
|
|
controller.isUp.value;
|
|
return CustomPaint(
|
|
// size: Size(scenceMapController.diagonal,
|
|
// scenceMapController.diagonal),
|
|
foregroundPainter:
|
|
DrawDirection(controller, scOffset, isDarkMode, isInit),
|
|
// child:
|
|
);
|
|
}),
|
|
),
|
|
));
|
|
});
|
|
// 桩点生成时返回按钮
|
|
var back = Obx(() {
|
|
// bug :有时候点击的位置不准确 8寸屏的是正常的
|
|
|
|
controller.centerOffset.value = scenceMapController.xy2Screen(
|
|
controller.centerXY.value.dx, controller.centerXY.value.dy);
|
|
|
|
if (isInit) {
|
|
controller.centerOffset.value = scenceMapController.xy2Screen(
|
|
controller.centerXY.value.dx, controller.centerXY.value.dy) -
|
|
scOffset;
|
|
}
|
|
print(
|
|
"中心${controller.centerOffset.value},${controller.centerXY.value},${scenceMapController.centerXY},$scOffset,$isInit");
|
|
print(scenceMapController.xy2Screen(
|
|
controller.centerXY.value.dx, controller.centerXY.value.dy));
|
|
|
|
return Positioned(
|
|
left: controller.isGenerate.value
|
|
? controller.centerOffset.value.dx -
|
|
25 +
|
|
(mapWidth / 2 - diagonal / 2)
|
|
: -50,
|
|
top: controller.isGenerate.value
|
|
? controller.centerOffset.value.dy -
|
|
20 +
|
|
(mapHeight / 2 - diagonal / 2)
|
|
// 20 为高一半
|
|
: -50,
|
|
width: 50,
|
|
height: 40,
|
|
child: ClipOval(
|
|
child: ElevatedButton(
|
|
style: ElevatedButton.styleFrom(
|
|
padding: EdgeInsets.zero,
|
|
shape: const CircleBorder(),
|
|
),
|
|
child: const Icon(Icons.keyboard_return),
|
|
onPressed: () {
|
|
pilecontroller.isRealViewCardVisible.value = true;
|
|
controller.isDirect.value = true;
|
|
},
|
|
),
|
|
));
|
|
});
|
|
return Stack(
|
|
children: [
|
|
Obx(() => AbsorbPointer(
|
|
absorbing: controller.isGenerate.value
|
|
? true
|
|
: false, //设置CenterLayout 内的GestureDetector 不生效
|
|
// child: const ScenceMapView(
|
|
// children: [],
|
|
// ),
|
|
child: TaskPage(), // 任务页面
|
|
// PassTrack(
|
|
// date: '',
|
|
// )
|
|
)),
|
|
center,
|
|
back,
|
|
PileGenerateCard1()
|
|
],
|
|
);
|
|
}
|
|
}
|