226 lines
7.4 KiB
Dart
226 lines
7.4 KiB
Dart
import 'dart:async';
|
|
import 'dart:math';
|
|
import 'dart:ui' as ui;
|
|
|
|
import 'package:cpnav/appbar.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:scence_map/scence_map.dart';
|
|
|
|
import '../../service/pile/device_type.dart';
|
|
import 'aimPointer.dart';
|
|
|
|
final SightController sight = Get.put(SightController());
|
|
|
|
class AimPointer extends StatefulWidget {
|
|
const AimPointer({super.key});
|
|
|
|
@override
|
|
State<AimPointer> createState() => _AimPointerState();
|
|
}
|
|
//CounterPointer 是一个自定义的 StatefulWidget 类。
|
|
//它通过重写 createState 方法来创建一个与之关联的 State 对象。
|
|
//createState 方法返回 _CounterPointerState(),这是一个 _CounterPointerState
|
|
//类的实例,用于管理 CounterPointer 的状态和生命周期。
|
|
|
|
class _AimPointerState extends State<AimPointer> {
|
|
// late final DeviceItemController item;
|
|
// late final double maprotation;
|
|
// late final Offset targetPoint;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
|
|
// map.disableMove.value = true;
|
|
// map.update();
|
|
}
|
|
|
|
String gradienter = "0"; //水平仪
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final Size size = MediaQuery.of(context).size;
|
|
MediaQueryData mediaQueryData =
|
|
MediaQueryData.fromView(WidgetsBinding.instance.window); //获取当前屏幕信息
|
|
final orientation = mediaQueryData.orientation; //获得设备方向
|
|
bool isPortrait = Orientation.portrait == orientation ? true : false;
|
|
double rectWidth = size.width;
|
|
final deviceType = getDeviceType(context);
|
|
|
|
// var dx = item.x - targetPoint.dx;
|
|
// var dy = item.y - targetPoint.dy;
|
|
// var left = dx * cos(maprotation) + dy * sin(maprotation);
|
|
// var top = -dx * sin(maprotation) + dy * cos(maprotation);
|
|
if (orientation == Orientation.landscape) {
|
|
rectWidth = size.width / 2 - 60;
|
|
if (deviceType == DeviceType.mobile) {
|
|
rectWidth = size.height - 130;
|
|
}
|
|
} else {
|
|
rectWidth = size.height / 2;
|
|
if (deviceType == DeviceType.mobile) {
|
|
rectWidth = size.width - 5;
|
|
}
|
|
}
|
|
bool isDarkMode = Theme.of(context).brightness == Brightness.dark;
|
|
List<Widget> children = [
|
|
SizedBox(
|
|
width: rectWidth,
|
|
height: rectWidth,
|
|
child: Card(
|
|
shape: RoundedRectangleBorder(
|
|
side: BorderSide(color: Colors.transparent, width: 0),
|
|
borderRadius: BorderRadius.circular(4.0), // 可以根据需要调整圆角半径
|
|
),
|
|
child: Stack(
|
|
children: [
|
|
Container(
|
|
width: rectWidth,
|
|
height: rectWidth,
|
|
clipBehavior: Clip.hardEdge, //圆形剪裁
|
|
decoration: BoxDecoration(
|
|
border: Border.all(
|
|
color: isDarkMode ? Colors.white : Colors.black),
|
|
borderRadius:
|
|
BorderRadius.all(Radius.circular(rectWidth / 2)),
|
|
),
|
|
child: const SightView(),
|
|
),
|
|
Positioned(
|
|
top: 0,
|
|
left: 10,
|
|
child: Obx(() {
|
|
return TextButton(
|
|
child: Text(
|
|
"${sight.plot.value}m",
|
|
style: const TextStyle(fontSize: 20),
|
|
),
|
|
onPressed: () {
|
|
if (sight.plot.value == 1) {
|
|
sight.plot.value = 2;
|
|
} else {
|
|
sight.plot.value = 1;
|
|
}
|
|
sight.update();
|
|
},
|
|
);
|
|
})),
|
|
Positioned(
|
|
top: 25,
|
|
right: 10,
|
|
child: TextButton(
|
|
child: Text(
|
|
"垂直度:$gradienter°",
|
|
style: const TextStyle(fontSize: 20),
|
|
),
|
|
onPressed: () {},
|
|
)),
|
|
Positioned(
|
|
right: 0,
|
|
top: 0,
|
|
child: IconButton(
|
|
icon: const Icon(Icons.close),
|
|
onPressed: () {
|
|
// 关闭按钮的回调函数
|
|
sight.isCardVisible.value = false;
|
|
},
|
|
),
|
|
),
|
|
Positioned(
|
|
// left: rectWidth / 2 + left / mapcontroller.pixel2MeterRatio,
|
|
// top: rectWidth / 2 - top / mapcontroller.pixel2MeterRatio,
|
|
left: 70,
|
|
top: 70,
|
|
// child: Obx(() {
|
|
// return Transform(
|
|
// // transform: Matrix4.identity()..rotateZ(item.rotation.value),
|
|
// transform: Matrix4.identity()..rotateZ(0),
|
|
// alignment: FractionalOffset.center,
|
|
// child: DevicePointer(item),
|
|
// );
|
|
// }),
|
|
|
|
child: DevicePointer(),
|
|
)
|
|
],
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(
|
|
width: 5,
|
|
height: 5,
|
|
),
|
|
const Expanded(
|
|
child: Text(""),
|
|
),
|
|
];
|
|
if (isPortrait) {
|
|
return Column(
|
|
children: children,
|
|
);
|
|
} else {
|
|
return Row(
|
|
children: children,
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
// 瞄准器卡片
|
|
class SightGview extends StatelessWidget {
|
|
const SightGview();
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final Size size = MediaQuery.of(context).size;
|
|
MediaQueryData mediaQueryData =
|
|
MediaQueryData.fromView(WidgetsBinding.instance.window); //获取当前屏幕信息
|
|
final orientation = mediaQueryData.orientation; //获得设备方向
|
|
double rectWidth = size.width;
|
|
final deviceType = getDeviceType(context);
|
|
if (orientation == Orientation.landscape) {
|
|
rectWidth = size.width / 2 - 60;
|
|
if (deviceType == DeviceType.mobile) {
|
|
rectWidth = size.height - 130;
|
|
}
|
|
} else {
|
|
rectWidth = size.height / 2;
|
|
if (deviceType == DeviceType.mobile) {
|
|
rectWidth = size.width - 5;
|
|
}
|
|
}
|
|
|
|
return Obx(() => Visibility(
|
|
visible: sight.isCardVisible.value,
|
|
child: Positioned(
|
|
left: sight.sightOffset.value.dx,
|
|
top: sight.sightOffset.value.dy,
|
|
width: rectWidth + 15,
|
|
height: rectWidth + 15,
|
|
child: GestureDetector(
|
|
onScaleStart: (details) {
|
|
// 正确计算初始偏移量:当前手指位置与卡片当前位置之间的差值
|
|
sight.sightInit.value =
|
|
details.localFocalPoint - sight.sightOffset.value;
|
|
//
|
|
//
|
|
//
|
|
print('sight.isCardVisible: ${sight.isCardVisible.value}');
|
|
},
|
|
onScaleUpdate: (details) {
|
|
// 使用初始偏移量来更新卡片的位置
|
|
sight.sightOffset.value =
|
|
details.localFocalPoint - sight.sightInit.value;
|
|
},
|
|
child: Container(
|
|
decoration: const BoxDecoration(color: Colors.transparent),
|
|
child: const Stack(children: [
|
|
Card(
|
|
color: Colors.transparent,
|
|
elevation: 5.0,
|
|
child: AimPointer(),
|
|
),
|
|
]))))));
|
|
}
|
|
}
|