200 lines
6.5 KiB
Dart
200 lines
6.5 KiB
Dart
import 'dart:async';
|
|
import 'dart:ui' as ui;
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:scence_map/controller.dart';
|
|
|
|
import '../modules/device_type.dart';
|
|
|
|
import '../draws/aim_pointer.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> {
|
|
@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);
|
|
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(
|
|
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: 10,
|
|
right: 10,
|
|
child: TextButton(
|
|
child: Text(
|
|
"垂直度:$gradienter°",
|
|
style: const TextStyle(fontSize: 20),
|
|
),
|
|
onPressed: () {},
|
|
)),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(
|
|
width: 5,
|
|
height: 5,
|
|
),
|
|
const Expanded(
|
|
child: Text(""),
|
|
),
|
|
];
|
|
if (isPortrait) {
|
|
return Column(
|
|
children: children,
|
|
);
|
|
} else {
|
|
return Row(
|
|
children: children,
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
// List<Widget> createDevice(ScenceMapController controller) {
|
|
// //用于生成设备的视图小部件列表
|
|
// if (controller.isDrag) {
|
|
// return [];
|
|
// }
|
|
// List<Widget> devices = [];
|
|
// controller.deviceList.forEach((key, item) {
|
|
// devices.add(Obx(() {
|
|
// Offset offset = controller.xy2Screen(
|
|
// gnsscontroller.pilerCenter.X, gnsscontroller.pilerCenter.Y);
|
|
|
|
// double carWidth = item.width / controller.pixel2MeterRatio;
|
|
// double carHeight = item.height / controller.pixel2MeterRatio;
|
|
// print("${offset.dx - carHeight * 2},${offset.dy - carWidth}");
|
|
// return Stack(
|
|
// children: [
|
|
// Obx(() {
|
|
// // item.update.value;
|
|
// gnsscontroller.locationUpdate.value;
|
|
|
|
// Offset offset = controller.xy2Screen(
|
|
// gnsscontroller.pilerCenter.X, gnsscontroller.pilerCenter.Y);
|
|
// return Positioned(
|
|
// left: offset.dx - carHeight * 3.5,
|
|
// top: offset.dy - carWidth / 2,
|
|
// // width: ,
|
|
// height: carWidth,
|
|
// child: Transform(
|
|
// transform: Matrix4.identity()
|
|
// // ..scale(item.scale)
|
|
|
|
// ..rotateZ(gnsscontroller.pilerCenter.rotation),
|
|
// alignment: FractionalOffset.center,
|
|
// // child: Image.network(
|
|
// // "http://v5.rdc.pub${item.image[item.status.value]}",
|
|
// // errorBuilder: (context, error, stackTrace) {
|
|
// // return Image.asset("")
|
|
|
|
// // child: Image.asset("images/pilerCar.png",
|
|
// // errorBuilder: (context, error, stackTrace) {
|
|
// // return Text('无法加载图片');
|
|
// // }
|
|
// // // width: item.width,
|
|
// // // height: item.height,
|
|
// // )
|
|
|
|
// child: Image.asset(
|
|
// "images/pilerCar.png",
|
|
// errorBuilder: (context, error, stackTrace) {
|
|
// return Text('无法加载图片');
|
|
// },
|
|
// // width: item.width,
|
|
// // height: item.height,
|
|
// ),
|
|
// ));
|
|
// }),
|
|
// Positioned(
|
|
// left: offset.dx,
|
|
// top: offset.dy,
|
|
// child: Transform(
|
|
// transform: Matrix4.identity()
|
|
// ..rotateZ(-controller.rotation.value),
|
|
// child: Column(
|
|
// children: [Text("设备:${item.name}")],
|
|
// ),
|
|
// ))
|
|
// ],
|
|
// );
|
|
// }));
|
|
// });
|
|
// return devices;
|
|
// }
|