import 'package:flutter/material.dart'; import 'package:gnssview/sky/device_type.dart'; import 'mulbutton.dart'; class SkyInfo extends StatelessWidget { final String lat; // 纬度 final String lon; // 经度 final String hdop; // 高程 final int status; // 定位状态 final int view; // 可见 final int use; // 使用 final String time; // 时间 const SkyInfo({ super.key, required this.lat, required this.lon, required this.hdop, required this.status, required this.view, required this.use, required this.time, }); @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: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [ // 创建行项的函数 rowItem(context, "北纬:", lat.contains("-") ? '$lat S ' : '$lat N '), rowItem(context, "东经:", lon.contains("-") ? '$lon W ' : '$lon E '), rowItem(context, "高程:", '$hdop 米'), rowItem(context, "定位状态:", ""), rowItem(context, "可见:", '$view'), rowItem(context, "使用:", '$use'), rowItem(context, "时间:", time), Row( mainAxisAlignment: MainAxisAlignment.end, children: [ MulButton( colors: const [ Colors.blue, Colors.red, Colors.green, Colors.orange ], onSelectionChanged: (selectedColors) { // 处理选中的颜色 print('选中的颜色: $selectedColors'); }, ), ], ), ]), )); } Widget rowItem(BuildContext context, String title, String text) => Row( children: [ FixedWidthTextWidget( width: 80, text: title, style: Theme.of(context).textTheme.titleLarge, ), Text( text, style: Theme.of(context).textTheme.titleLarge, ), ], ); } class FixedWidthTextWidget extends StatelessWidget { final String text; final double width; final TextStyle? style; FixedWidthTextWidget({ super.key, required this.text, this.width = 80, this.style, }); TextStyle? textStyle; @override Widget build(BuildContext context) { final deviceType = getDeviceType(context); double dynamicWidth = deviceType == DeviceType.mobile ? 0 : 50; 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, ), ); } }