gnssview/lib/sky/sky_info.dart

232 lines
7.8 KiB
Dart
Raw Permalink Normal View History

2024-08-06 17:41:15 +08:00
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:get/get_connect/http/src/utils/utils.dart';
import 'package:intl/intl.dart';
import 'package:gnssview/sky/device_type.dart';
import '../Controller/gnss_controller.dart';
import '../quality/signalQuality_page.dart';
import 'mulbutton.dart';
import 'sky_plot.dart';
class SkyInfo extends StatelessWidget {
late final GnssController controller;
SkyInfo({super.key}) {
controller = Get.find<GnssController>();
}
@override
Widget build(BuildContext context) {
final isPortrait =
MediaQuery.of(context).orientation == Orientation.portrait;
return Theme(
data: ThemeData(
textTheme: const TextTheme(
titleLarge: TextStyle(
fontSize: 30,
fontWeight: FontWeight.normal,
),
),
),
child: Container(
margin: const EdgeInsets.only(left: 5),
padding: const EdgeInsets.symmetric(vertical: 10),
alignment: Alignment.centerLeft,
child: Obx(() {
controller.locationUpdate.value;
final location = controller.locationData;
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// 创建行项的函数
rowItem(context, "纬度:", '${location?.latitude}'),
rowItem(context, "经度:", '${location?.longitude}'),
rowItem(context, "高程:", '${location?.altitude}'),
rowItem(context, "水平精度:", '${location?.hdop}'),
rowItem(context, "垂直精度:", '${location?.vdop}'),
rowItem(context, "定位状态:", '${location?.fixQuality}'),
rowItem(context, "可见卫星数:", '${location?.numberSv}'),
rowItem(context, "使用卫星数:", '${location?.numberSa}'),
rowItem(
context,
"时间: ",
location == null
? 'null'
: DateFormat('yyyy-MM-dd HH:mm:ss')
.format(location.time)),
]);
})));
}
Widget rowItem(BuildContext context, String title, String text) => Row(
children: [
FixedWidthText(
width: 100,
text: title,
style: Theme.of(context).textTheme.titleLarge,
),
Text(
text,
style: Theme.of(context).textTheme.titleLarge,
),
],
);
}
class FixedWidthText extends StatelessWidget {
final String text;
final double width;
final TextStyle? style;
const FixedWidthText({
super.key,
required this.text,
this.width = 100,
this.style,
});
@override
Widget build(BuildContext context) {
final deviceType = getDeviceType(context);
double dynamicWidth = deviceType == DeviceType.mobile ? 0 : 50;
TextStyle textStyle;
if (style != null) {
textStyle =
style!.copyWith(fontSize: deviceType == DeviceType.mobile ? 16 : 20);
} else {
textStyle =
TextStyle(fontSize: deviceType == DeviceType.mobile ? 16 : 20);
}
return Container(
margin: const EdgeInsets.symmetric(horizontal: 3),
width: width + dynamicWidth,
child: Text(
text,
style: textStyle,
),
);
}
}
class SkyInfoPlotPage extends StatelessWidget {
late final GnssController controller;
SkyInfoPlotPage({super.key}) {
controller = Get.find<GnssController>();
}
@override
Widget build(BuildContext context) {
final orientation = MediaQuery.of(context).orientation;
bool isPortrait = orientation == Orientation.portrait;
return Scaffold(
appBar: AppBar(
toolbarHeight: 58,
title: Container(
alignment: Alignment.center,
child: const Text(
'天空图',
),
),
leading: IconButton(
icon: Icon(Icons.arrow_back),
onPressed: () {
// Navigator.push(
// context,
// MaterialPageRoute(builder: (context) => SignalQuality()),
// );
},
),
actions: [
IconButton(
icon: Container(
padding: EdgeInsets.symmetric(horizontal: 8.0, vertical: 4.0),
decoration: BoxDecoration(
border: Border.all(color: const Color.fromARGB(255, 0, 0, 0)),
borderRadius: BorderRadius.circular(4.0),
),
child: const Text(
'信噪比',
style: TextStyle(color: Color.fromARGB(255, 0, 0, 0), fontSize: 16.0),
),
),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SignalQuality()),
);
},
),
],
),
body: isPortrait
? Stack(
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Expanded(
child: SkyInfo(),
),
],
),
Positioned(
left: 10.0, // 设置 MulButton 的左边距
top: 270.0, // 设置 MulButton 的下边距
child: MulButton(
signalColorList: const [
Color.fromARGB(255, 255, 0, 0),
Color.fromARGB(255, 0, 255, 0),
Color.fromARGB(255, 0, 0, 255),
Color.fromARGB(255, 146, 73, 206),
Color.fromRGBO(13, 179, 179, 1),
],
onSelectionChanged: (key, value) {
controller.selectedSignal[key] = value;
},
),
),
Positioned(
left: 40,
bottom: 5.0, // 设置 SkyPlotPage 的上边距
child: Container(
width: 450, // 设置 SkyPlotPage 的宽度
height: 450, // 设置 SkyPlotPage 的高度
child: SkyPlotPage(),
),
),
],
)
: Stack(
alignment: Alignment.bottomLeft, // 设置 Stack 的对齐方式
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Flexible(
child: SkyInfo(),
),
Expanded(
child: SkyPlotPage(),
),
],
),
Padding(
padding: const EdgeInsets.all(8.0), // 调整间距
child: MulButton(
signalColorList: const [
Color.fromARGB(255, 255, 0, 0),
Color.fromARGB(255, 0, 255, 0),
Color.fromARGB(255, 0, 0, 255),
Color.fromARGB(255, 146, 73, 206),
Color.fromRGBO(13, 179, 179, 1),
],
onSelectionChanged: (key, value) {
controller.selectedSignal[key] = value;
},
),
),
],
));
}
}