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'; import 'sky_plot.dart'; class SkyInfo extends StatelessWidget { late final GnssController controller; SkyInfo({super.key}) { controller = Get.find(); } @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( signalColorList: const [ Color.fromARGB(255, 255, 0, 0), Color.fromARGB(255, 0, 255, 0), Color.fromARGB(255, 0, 0, 255), Color.fromARGB(255, 255, 255, 0), Color.fromARGB(255, 0, 255, 255) ], 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, ), ); } } class SkyInfoPlotPage extends StatelessWidget { @override Widget build(BuildContext context) { final orientation = MediaQuery.of(context).orientation; bool isPortrait = orientation == Orientation.portrait; return isPortrait ? Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ Expanded( child: SkyInfo(), ), Expanded( child: SkyPlotPage(), ), ], ) : Row( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ Expanded( child: SkyInfo(), ), Expanded( child: SkyPlotPage(), ), ], ); } }