232 lines
8.3 KiB
Dart
232 lines
8.3 KiB
Dart
import 'dart:math';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import '../counter_pointer/sight.dart';
|
|
import '../draws/data_type.dart';
|
|
import '../draws/scence_map.dart';
|
|
import '../getx/polyon.dart';
|
|
import 'controller.dart';
|
|
import 'direction.dart';
|
|
import 'polyon.dart';
|
|
import 'real_data.dart';
|
|
import 'real_device.dart';
|
|
|
|
class HomeView extends GetView<PlumDataController> {
|
|
const HomeView({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
ScenceMapController scenceMapController = Get.find<ScenceMapController>();
|
|
PolyonController polyonController = Get.find<PolyonController>();
|
|
List<Widget> children = [];
|
|
final size = MediaQuery.of(context).size;
|
|
return OrientationBuilder(builder: ((context, orientation) {
|
|
bool isPortrait = Orientation.portrait == orientation ? true : false;
|
|
double topHeight = isPortrait ? size.height / 6 : 0;
|
|
if (isPortrait) {
|
|
children = [const SightGview()];
|
|
} else {
|
|
children = [];
|
|
}
|
|
// 中间
|
|
var center = Obx(() {
|
|
// 桩点生成
|
|
if (controller.isGenerate.value) {
|
|
return GestureDetector(
|
|
onTapDown: (TapDownDetails details) {
|
|
if (controller.checkValue.value == "checkPile") {
|
|
controller.centerOffset.value = details.localPosition;
|
|
double diagonal = scenceMapController.diagonal;
|
|
double mapWidth = scenceMapController.width;
|
|
double mapHeight = scenceMapController.height;
|
|
Offset offset = Offset(
|
|
mapWidth / 2 - diagonal / 2, mapHeight / 2 - diagonal / 2);
|
|
Offset sc2xy = scenceMapController
|
|
.screen2xy0(details.localPosition - offset);
|
|
controller.centerXY.value = sc2xy;
|
|
HyRecordItem? 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 = "未找到";
|
|
}
|
|
showDialog(
|
|
context: context,
|
|
barrierDismissible: false,
|
|
builder: (BuildContext context) {
|
|
return const GenerateDialog();
|
|
});
|
|
}
|
|
},
|
|
onScaleStart: (details) {
|
|
controller.isUp.value = false;
|
|
if (controller.checkValue.value != "checkPile") {
|
|
controller.linePoint.value = details.localFocalPoint;
|
|
}
|
|
controller.shouldPaint.value = true;
|
|
},
|
|
onScaleUpdate: (details) {
|
|
controller.shouldPaint.value = true;
|
|
if (controller.checkValue.value != "checkPile") {
|
|
if (controller.linePoint.value != details.localFocalPoint) {
|
|
controller.updateLinePoint(details.localFocalPoint);
|
|
}
|
|
}
|
|
},
|
|
onScaleEnd: (details) {
|
|
double deg = (atan2(
|
|
controller.linePoint.value.dy -
|
|
controller.centerOffset.value.dy,
|
|
controller.linePoint.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;
|
|
controller.shouldPaint.value = false;
|
|
|
|
},
|
|
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.linePoint.value;
|
|
List<Widget> scenceMapViewChildren = [];
|
|
if (controller.isGenerate.value) {
|
|
scenceMapViewChildren = [];
|
|
} else {
|
|
scenceMapViewChildren = [const SightGview()];
|
|
}
|
|
return CustomPaint(
|
|
foregroundPainter: DrawDirection(controller),
|
|
child: AbsorbPointer(
|
|
absorbing: true, //设置CenterLayout 内的GestureDetector 不生效
|
|
child: ScenceMapView(scenceMapViewChildren),
|
|
));
|
|
}),
|
|
),
|
|
);
|
|
// 多边形
|
|
} else if (polyonController.isRuler.value) {
|
|
return const PolyonView( ScenceMapView([]));
|
|
} else {
|
|
return ScenceMapView(children);
|
|
}
|
|
});
|
|
// 桩点生成时返回按钮
|
|
var back = Obx(() => Positioned(
|
|
left: controller.isGenerate.value
|
|
? controller.centerOffset.value.dx - 25 //宽一半
|
|
: -50,
|
|
top: controller.isGenerate.value
|
|
? controller.centerOffset.value.dy + topHeight - 20 // 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: () {
|
|
showDialog(
|
|
context: context,
|
|
barrierDismissible: false,
|
|
builder: (BuildContext context) {
|
|
return const GenerateDialog();
|
|
});
|
|
controller.isDirect.value = false;
|
|
},
|
|
),
|
|
)));
|
|
// 竖屏
|
|
var portraitWidget = Column(
|
|
children: [
|
|
Expanded(flex: 1, child: RealDataVIew()),
|
|
Expanded(flex: 5, child: center),
|
|
],
|
|
);
|
|
// 横屏
|
|
var landscapeWidget = Row(
|
|
children: [
|
|
Expanded(flex: 2, child: RealDataVIew()),
|
|
Expanded(flex: 5, child: center),
|
|
const Expanded(flex: 2, child: RealDeviceView()),
|
|
],
|
|
);
|
|
// 瞄准器
|
|
var sightWidegt = Positioned(
|
|
width: size.width / 9 * 2,
|
|
height: size.width / 9 * 2,
|
|
bottom: 0,
|
|
left: 0,
|
|
child: Container(
|
|
decoration: const BoxDecoration(color: Colors.transparent),
|
|
child: const Card(
|
|
elevation: 5.0,
|
|
child: SightView(),
|
|
)));
|
|
return Stack(
|
|
children: [
|
|
if (isPortrait) portraitWidget else landscapeWidget,
|
|
back,
|
|
if (!isPortrait) sightWidegt,
|
|
],
|
|
);
|
|
}));
|
|
}
|
|
}
|
|
|
|
// 瞄准器
|
|
class SightGview extends GetView<SightController> {
|
|
const SightGview({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final Size size = MediaQuery.of(context).size;
|
|
return Obx(() => Positioned(
|
|
left: controller.sightOffset.value.dx,
|
|
top: controller.sightOffset.value.dy,
|
|
width: size.width / 5 * 2,
|
|
height: size.width / 5 * 2,
|
|
child: GestureDetector(
|
|
onScaleStart: ((details) {
|
|
// 17 这个值不知原因?
|
|
controller.initSight.value =
|
|
Offset(0, size.width / 5 * 2 - 17) + details.localFocalPoint;
|
|
controller.sightOffset.value =
|
|
details.focalPoint - controller.initSight.value;
|
|
}),
|
|
onScaleUpdate: (details) {
|
|
controller.sightOffset.value =
|
|
details.focalPoint - controller.initSight.value;
|
|
},
|
|
child: Container(
|
|
decoration: const BoxDecoration(color: Colors.transparent),
|
|
child: const Card(
|
|
elevation: 5.0,
|
|
child: SightView(),
|
|
)),
|
|
),
|
|
));
|
|
}
|
|
}
|