gnssview_old/lib/sky/sky_info.dart
2024-07-31 23:37:51 +08:00

123 lines
4.0 KiB
Dart

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:intl/intl.dart';
import 'package:gnssview/sky/device_type.dart';
import '../Controller/gnss_controller.dart';
import 'mulbutton.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: 20),
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)),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
MulButton(
colors: const [
Colors.blue,
Colors.red,
Colors.green,
Colors.orange
],
onSelectionChanged: (int index, bool value) {
controller.selectedSignal[index] = value;
},
),
],
),
]);
})));
}
Widget rowItem(BuildContext context, String title, String text) => Row(
children: [
FixedWidthText(
width: 80,
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 = 80,
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,
),
);
}
}