图表初始化
This commit is contained in:
@@ -1,8 +1,10 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:fl_chart/fl_chart.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:syncfusion_flutter_gauges/gauges.dart';
|
||||||
|
|
||||||
import '../../../../core/app/app_user_cubit.dart';
|
import '../../../../core/app/app_user_cubit.dart';
|
||||||
import '../../../../core/di/injection.dart';
|
import '../../../../core/di/injection.dart';
|
||||||
@@ -21,6 +23,41 @@ class RunningStatusPage extends StatefulWidget {
|
|||||||
|
|
||||||
class _RunningStatusPageState extends State<RunningStatusPage> {
|
class _RunningStatusPageState extends State<RunningStatusPage> {
|
||||||
bool _isCardView = true;
|
bool _isCardView = true;
|
||||||
|
bool _chipGaugeMode = true;
|
||||||
|
|
||||||
|
// 图表历史数据
|
||||||
|
final List<FlSpot> _leftMeasureHistory = [];
|
||||||
|
final List<FlSpot> _rightMeasureHistory = [];
|
||||||
|
final List<FlSpot> _leftTargetHistory = [];
|
||||||
|
final List<FlSpot> _rightTargetHistory = [];
|
||||||
|
final List<FlSpot> _leftCurrentHistory = [];
|
||||||
|
final List<FlSpot> _rightCurrentHistory = [];
|
||||||
|
final List<FlSpot> _leftTempHistory = [];
|
||||||
|
final List<FlSpot> _rightTempHistory = [];
|
||||||
|
final List<FlSpot> _knifeHistory = [];
|
||||||
|
final List<FlSpot> _chipTempHistory = [];
|
||||||
|
final List<FlSpot> _voltageHistory = [];
|
||||||
|
|
||||||
|
double _timeIndex = 0;
|
||||||
|
|
||||||
|
// 限制列表长度,防止数据过多
|
||||||
|
void _limit(List<FlSpot> list, {int max = 30}) {
|
||||||
|
if (list.length > max) list.removeAt(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 刷新数据方法(移到正确位置)
|
||||||
|
void _refreshDeviceData() {
|
||||||
|
final deviceState = context.read<DevicesCubit>().state;
|
||||||
|
final currentDevice = deviceState.selectedDevice;
|
||||||
|
|
||||||
|
if (currentDevice != null) {
|
||||||
|
// 触发Bloc刷新数据
|
||||||
|
// context.read<DeviceStatusBloc>().add(RefreshDeviceStatus(deviceId: currentDevice.id));
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text("数据刷新成功!"), duration: Duration(seconds: 1)));
|
||||||
|
} else {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text("暂无设备,无法刷新"), duration: Duration(seconds: 1)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 解析定位质量数值为文字描述
|
// 解析定位质量数值为文字描述
|
||||||
String _parseLocationQuality(int locationValue) {
|
String _parseLocationQuality(int locationValue) {
|
||||||
@@ -36,161 +73,209 @@ class _RunningStatusPageState extends State<RunningStatusPage> {
|
|||||||
case 5:
|
case 5:
|
||||||
return 'RTK 浮点解';
|
return 'RTK 浮点解';
|
||||||
default:
|
default:
|
||||||
return '未知($locationValue)'; // 处理未定义的数值,避免显示空值
|
return '未知($locationValue)';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
// 追加图表数据
|
||||||
Widget build(BuildContext context) {
|
void _appendChartData(DeviceStatusUpdated state) {
|
||||||
final deviceState = context.read<DevicesCubit>().state;
|
final status = state.status;
|
||||||
final currentDevice = deviceState.selectedDevice;
|
|
||||||
|
|
||||||
if (currentDevice == null) {
|
// 添加速度数据
|
||||||
return const Scaffold(body: Center(child: Text("加载中...")));
|
_leftTargetHistory.add(FlSpot(_timeIndex, status.leftTargetSpeed));
|
||||||
}
|
_rightTargetHistory.add(FlSpot(_timeIndex, status.rightTargetSpeed));
|
||||||
|
_leftMeasureHistory.add(FlSpot(_timeIndex, status.leftMeasureSpeed));
|
||||||
|
_rightMeasureHistory.add(FlSpot(_timeIndex, status.rightMeasureSpeed));
|
||||||
|
|
||||||
return Scaffold(
|
// 添加电流数据
|
||||||
backgroundColor: const Color(0xFFF7F7F7),
|
_leftCurrentHistory.add(FlSpot(_timeIndex, status.leftCurrent));
|
||||||
body: CustomScrollView(
|
_rightCurrentHistory.add(FlSpot(_timeIndex, status.rightCurrent));
|
||||||
physics: const BouncingScrollPhysics(),
|
|
||||||
slivers: [
|
|
||||||
SliverAppBar(
|
|
||||||
backgroundColor: const Color(0xFF1677FF),
|
|
||||||
pinned: true,
|
|
||||||
centerTitle: true,
|
|
||||||
elevation: 0,
|
|
||||||
title: const Text(
|
|
||||||
"设备数据监控",
|
|
||||||
style: TextStyle(color: Colors.white, fontSize: 18, fontWeight: FontWeight.bold),
|
|
||||||
),
|
|
||||||
leading: IconButton(
|
|
||||||
icon: const Icon(Icons.arrow_back, color: Colors.white),
|
|
||||||
onPressed: () => Navigator.pop(context),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
|
|
||||||
BlocBuilder<DeviceStatusBloc, DeviceStatusState>(
|
// 添加温度数据
|
||||||
builder: (context, state) {
|
_leftTempHistory.add(FlSpot(_timeIndex, status.leftMotorTemp));
|
||||||
String qual = '--';
|
_rightTempHistory.add(FlSpot(_timeIndex, status.rightMotorTemp));
|
||||||
String satelliteCnt = '--';
|
|
||||||
String headingStatus = "--";
|
|
||||||
|
|
||||||
if (state is DeviceStatusUpdated) {
|
// 添加割刀速度
|
||||||
headingStatus = state.status.headingStatus == 0 ? '未初始化' : '已初始化';
|
_knifeHistory.add(FlSpot(_timeIndex, double.tryParse(status.knifeCuttingSpeed) ?? 0));
|
||||||
// 强制转换为整型并解析定位质量
|
|
||||||
int qualValue = 0;
|
|
||||||
try {
|
|
||||||
qualValue = int.parse(state.status.qual.toString());
|
|
||||||
} catch (e) {
|
|
||||||
qualValue = 0;
|
|
||||||
}
|
|
||||||
qual = _parseLocationQuality(qualValue);
|
|
||||||
satelliteCnt = state.status.satelliteCnt.toString();
|
|
||||||
} else if (state is DeviceStatusError) {
|
|
||||||
qual = '-';
|
|
||||||
satelliteCnt = '-';
|
|
||||||
headingStatus = '-';
|
|
||||||
}
|
|
||||||
|
|
||||||
return SliverToBoxAdapter(
|
// 添加芯片温度和电压
|
||||||
child: Container(
|
_chipTempHistory.add(FlSpot(_timeIndex, status.chipTemp));
|
||||||
color: Colors.white,
|
_voltageHistory.add(FlSpot(_timeIndex, double.tryParse(status.battery) ?? 0));
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10), // 减小内边距
|
|
||||||
child: Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
||||||
children: [
|
|
||||||
// 优化1:减小字体大小到12,设置最大宽度,防止溢出
|
|
||||||
Expanded(
|
|
||||||
flex: 3,
|
|
||||||
child: Text("航向角状态:$headingStatus", style: const TextStyle(fontSize: 12), maxLines: 1, overflow: TextOverflow.ellipsis),
|
|
||||||
),
|
|
||||||
// 优化2:定位质量列,减小字体,设置最大宽度
|
|
||||||
Expanded(
|
|
||||||
flex: 4,
|
|
||||||
child: Text(
|
|
||||||
"定位质量:$qual",
|
|
||||||
style: const TextStyle(fontSize: 12),
|
|
||||||
maxLines: 1,
|
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
// 优化3:卫星数列,减小字体,设置最大宽度
|
|
||||||
Expanded(
|
|
||||||
flex: 2,
|
|
||||||
child: Text(
|
|
||||||
"卫星数:$satelliteCnt",
|
|
||||||
style: const TextStyle(fontSize: 12),
|
|
||||||
maxLines: 1,
|
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
textAlign: TextAlign.right,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
|
|
||||||
SliverToBoxAdapter(
|
_timeIndex += 1;
|
||||||
child: Container(
|
|
||||||
color: Colors.white,
|
// 限制数据长度
|
||||||
margin: const EdgeInsets.only(top: 8),
|
_limit(_leftTargetHistory);
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
_limit(_rightTargetHistory);
|
||||||
child: Row(
|
_limit(_leftMeasureHistory);
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
_limit(_rightMeasureHistory);
|
||||||
children: [
|
_limit(_leftCurrentHistory);
|
||||||
Row(
|
_limit(_rightCurrentHistory);
|
||||||
children: [
|
_limit(_leftTempHistory);
|
||||||
GestureDetector(
|
_limit(_rightTempHistory);
|
||||||
onTap: () => setState(() => _isCardView = true),
|
_limit(_knifeHistory);
|
||||||
child: _buildTab("卡片", isActive: _isCardView),
|
_limit(_chipTempHistory);
|
||||||
),
|
_limit(_voltageHistory);
|
||||||
const SizedBox(width: 24),
|
}
|
||||||
GestureDetector(
|
|
||||||
onTap: () => setState(() => _isCardView = false),
|
// 构建间距组件
|
||||||
child: _buildTab("图表", isActive: !_isCardView),
|
Widget _gap({double height = 20}) {
|
||||||
),
|
return SizedBox(height: height);
|
||||||
],
|
}
|
||||||
),
|
|
||||||
ElevatedButton(
|
// 构建折线图
|
||||||
style: ElevatedButton.styleFrom(
|
Widget _buildLineChart({required String title, required List<LineChartBarData> lines, double? minY, double? maxY}) {
|
||||||
backgroundColor: const Color(0xFF1677FF),
|
return Column(
|
||||||
foregroundColor: Colors.white,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(4)),
|
children: [
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
Text(title, style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),
|
||||||
),
|
const SizedBox(height: 12),
|
||||||
onPressed: _refreshDeviceData,
|
SizedBox(
|
||||||
child: const Text("刷新数据", style: TextStyle(fontSize: 14)),
|
height: 220,
|
||||||
),
|
child: LineChart(
|
||||||
],
|
LineChartData(
|
||||||
|
minY: minY,
|
||||||
|
maxY: maxY,
|
||||||
|
lineBarsData: lines,
|
||||||
|
gridData: const FlGridData(show: true),
|
||||||
|
borderData:FlBorderData(show: true),
|
||||||
|
titlesData: const FlTitlesData(
|
||||||
|
leftTitles: AxisTitles(sideTitles: SideTitles(showTitles: true)),
|
||||||
|
bottomTitles: AxisTitles(sideTitles: SideTitles(showTitles: true)),
|
||||||
|
rightTitles: AxisTitles(sideTitles: SideTitles(showTitles: false)),
|
||||||
|
topTitles: AxisTitles(sideTitles: SideTitles(showTitles: false)),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
SliverFillRemaining(
|
// 构建折线
|
||||||
child: BlocBuilder<DeviceStatusBloc, DeviceStatusState>(
|
LineChartBarData _line(List<FlSpot> data, Color color) {
|
||||||
builder: (context, state) {
|
return LineChartBarData(
|
||||||
return Container(
|
spots: data,
|
||||||
margin: const EdgeInsets.all(16),
|
color: color,
|
||||||
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(8)),
|
isCurved: true,
|
||||||
child: _isCardView ? _buildCardContentView(state) : _buildChartContentView(),
|
barWidth: 2,
|
||||||
);
|
dotData: const FlDotData(show: false),
|
||||||
},
|
belowBarData: BarAreaData(show: false),
|
||||||
),
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 左右轮测量速度图表
|
||||||
|
Widget _buildSpeedMeasureChart() {
|
||||||
|
return _buildLineChart(
|
||||||
|
title: "左右轮测量速度 (rpm)",
|
||||||
|
minY: -3000,
|
||||||
|
maxY: 3000,
|
||||||
|
lines: [_line(_leftMeasureHistory, Colors.blue), _line(_rightMeasureHistory, Colors.red)],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 左右轮目标速度图表
|
||||||
|
Widget _buildSpeedTargetChart() {
|
||||||
|
return _buildLineChart(
|
||||||
|
title: "左右轮目标速度 (rpm)",
|
||||||
|
minY: -3000,
|
||||||
|
maxY: 3000,
|
||||||
|
lines: [_line(_leftTargetHistory, Colors.green), _line(_rightTargetHistory, Colors.orange)],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 电流图表
|
||||||
|
Widget _buildCurrentChart() {
|
||||||
|
return _buildLineChart(
|
||||||
|
title: "左右轮电流 (A)",
|
||||||
|
minY: 0,
|
||||||
|
maxY: 100,
|
||||||
|
lines: [_line(_leftCurrentHistory, Colors.purple), _line(_rightCurrentHistory, Colors.teal)],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 电机温度图表
|
||||||
|
Widget _buildMotorTempChart() {
|
||||||
|
return _buildLineChart(
|
||||||
|
title: "左右轮电机温度 (°C)",
|
||||||
|
minY: 0,
|
||||||
|
maxY: 120,
|
||||||
|
lines: [_line(_leftTempHistory, Colors.deepOrange), _line(_rightTempHistory, Colors.brown)],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 割刀速度图表
|
||||||
|
Widget _buildKnifeSpeedChart() {
|
||||||
|
return _buildLineChart(title: "割刀速度 (rpm)", minY: 0, maxY: 3000, lines: [_line(_knifeHistory, Colors.indigo)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 芯片温度/电压面板
|
||||||
|
Widget _buildChipTempVoltagePanel(DeviceStatusUpdated state) {
|
||||||
|
return Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
const Text("芯片温度 / 电压", style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),
|
||||||
|
Switch(value: _chipGaugeMode, onChanged: (v) => setState(() => _chipGaugeMode = v)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
_chipGaugeMode
|
||||||
|
? Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||||
|
children: [_buildGauge(state.status.chipTemp, 0, 120, "芯片温度 (°C)"), _buildGauge(double.parse(state.status.battery), 0, 100, "电量 (%)")],
|
||||||
|
)
|
||||||
|
: _buildLineChart(title: "最近30次数据", lines: [_line(_chipTempHistory, Colors.red), _line(_voltageHistory, Colors.blue)]),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 航向角仪表盘
|
||||||
|
Widget _buildHeadingGauge(DeviceStatusUpdated state) {
|
||||||
|
return Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
const Text("航向角", style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
Center(child: _buildGauge(state.status.yaw, 0, 360, "航向角 (°)")),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建仪表盘
|
||||||
|
Widget _buildGauge(double value, double min, double max, String label) {
|
||||||
|
return SizedBox(
|
||||||
|
width: 150,
|
||||||
|
height: 150,
|
||||||
|
child: SfRadialGauge(
|
||||||
|
title: GaugeTitle(text: label),
|
||||||
|
axes: [
|
||||||
|
RadialAxis(
|
||||||
|
minimum: min,
|
||||||
|
maximum: max,
|
||||||
|
pointers: [NeedlePointer(value: value)],
|
||||||
|
annotations: [
|
||||||
|
GaugeAnnotation(
|
||||||
|
widget: Text(value.toStringAsFixed(1), style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),
|
||||||
|
angle: 90,
|
||||||
|
positionFactor: 0.5,
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 构建选项卡
|
||||||
Widget _buildTab(String title, {required bool isActive}) {
|
Widget _buildTab(String title, {required bool isActive}) {
|
||||||
return Text(
|
return Text(
|
||||||
title,
|
title,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: isActive ? const Color(0xFF1677FF) : const Color(0xFF666666),
|
color: isActive ? const Color(0xFF1677FF) : const Color(0xFF666666),
|
||||||
fontSize: 16, // 选项卡字体从18减小到16
|
fontSize: 16,
|
||||||
fontWeight: isActive ? FontWeight.bold : FontWeight.normal,
|
fontWeight: isActive ? FontWeight.bold : FontWeight.normal,
|
||||||
decoration: isActive ? TextDecoration.underline : null,
|
decoration: isActive ? TextDecoration.underline : null,
|
||||||
decorationColor: const Color(0xFF1677FF),
|
decorationColor: const Color(0xFF1677FF),
|
||||||
@@ -202,14 +287,13 @@ class _RunningStatusPageState extends State<RunningStatusPage> {
|
|||||||
// 电机参数表格
|
// 电机参数表格
|
||||||
Widget _buildMotorTable(DeviceStatusUpdated state) {
|
Widget _buildMotorTable(DeviceStatusUpdated state) {
|
||||||
final status = state.status;
|
final status = state.status;
|
||||||
print(state);
|
|
||||||
|
|
||||||
return Column(
|
return Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
const Padding(
|
const Padding(
|
||||||
padding: EdgeInsets.symmetric(vertical: 12),
|
padding: EdgeInsets.symmetric(vertical: 12),
|
||||||
child: Text("电机参数", style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)), // 从20减小到18
|
child: Text("电机参数", style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
|
||||||
),
|
),
|
||||||
Table(
|
Table(
|
||||||
border: TableBorder.all(color: const Color(0xFFE5E5E5)),
|
border: TableBorder.all(color: const Color(0xFFE5E5E5)),
|
||||||
@@ -262,7 +346,7 @@ class _RunningStatusPageState extends State<RunningStatusPage> {
|
|||||||
children: [
|
children: [
|
||||||
const Padding(
|
const Padding(
|
||||||
padding: EdgeInsets.symmetric(vertical: 12),
|
padding: EdgeInsets.symmetric(vertical: 12),
|
||||||
child: Text("其他参数", style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)), // 从20减小到18
|
child: Text("其他参数", style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
|
||||||
),
|
),
|
||||||
Table(
|
Table(
|
||||||
border: TableBorder.all(color: const Color(0xFFE5E5E5)),
|
border: TableBorder.all(color: const Color(0xFFE5E5E5)),
|
||||||
@@ -286,15 +370,16 @@ class _RunningStatusPageState extends State<RunningStatusPage> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 表格单元格
|
||||||
Widget _buildTableCell(String text, {bool isHeader = false}) {
|
Widget _buildTableCell(String text, {bool isHeader = false}) {
|
||||||
return TableCell(
|
return TableCell(
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 6), // 减小表格内边距
|
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 6),
|
||||||
child: Text(
|
child: Text(
|
||||||
text,
|
text,
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 14, // 表格字体从16减小到14
|
fontSize: 14,
|
||||||
color: isHeader ? const Color(0xFF333333) : const Color(0xFF666666),
|
color: isHeader ? const Color(0xFF333333) : const Color(0xFF666666),
|
||||||
fontWeight: isHeader ? FontWeight.bold : FontWeight.normal,
|
fontWeight: isHeader ? FontWeight.bold : FontWeight.normal,
|
||||||
),
|
),
|
||||||
@@ -303,6 +388,7 @@ class _RunningStatusPageState extends State<RunningStatusPage> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 卡片视图
|
||||||
Widget _buildCardContentView(DeviceStatusState state) {
|
Widget _buildCardContentView(DeviceStatusState state) {
|
||||||
if (state is DeviceStatusUpdated) {
|
if (state is DeviceStatusUpdated) {
|
||||||
return SingleChildScrollView(
|
return SingleChildScrollView(
|
||||||
@@ -318,29 +404,180 @@ class _RunningStatusPageState extends State<RunningStatusPage> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildChartContentView() {
|
// 图表视图
|
||||||
return const Center(
|
Widget _buildChartContentView(DeviceStatusState state) {
|
||||||
|
if (state is! DeviceStatusUpdated) {
|
||||||
|
return const Center(child: CircularProgressIndicator());
|
||||||
|
}
|
||||||
|
|
||||||
|
return SingleChildScrollView(
|
||||||
|
padding: const EdgeInsets.all(16),
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: [
|
children: [
|
||||||
Text("图表视图", style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
|
_buildSpeedMeasureChart(),
|
||||||
SizedBox(height: 16),
|
_gap(),
|
||||||
Text("可接入 fl_chart / charts_flutter 实现折线图/柱状图", style: TextStyle(color: Color(0xFF999999), fontSize: 14)),
|
_buildSpeedTargetChart(),
|
||||||
|
_gap(),
|
||||||
|
_buildCurrentChart(),
|
||||||
|
_gap(),
|
||||||
|
_buildMotorTempChart(),
|
||||||
|
_gap(),
|
||||||
|
_buildKnifeSpeedChart(),
|
||||||
|
_gap(),
|
||||||
|
_buildChipTempVoltagePanel(state),
|
||||||
|
_gap(),
|
||||||
|
_buildHeadingGauge(state),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _refreshDeviceData() {
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
final deviceState = context.read<DevicesCubit>().state;
|
final deviceState = context.read<DevicesCubit>().state;
|
||||||
final currentDevice = deviceState.selectedDevice;
|
final currentDevice = deviceState.selectedDevice;
|
||||||
|
|
||||||
if (currentDevice != null) {
|
if (currentDevice == null) {
|
||||||
// 这里可以触发 Bloc 事件来刷新数据
|
return const Scaffold(body: Center(child: Text("加载中...")));
|
||||||
// context.read<DeviceStatusBloc>().add(RefreshDeviceStatus(deviceId: currentDevice.id));
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text("数据刷新成功!"), duration: Duration(seconds: 1)));
|
|
||||||
} else {
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text("暂无设备,无法刷新"), duration: Duration(seconds: 1)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Scaffold(
|
||||||
|
backgroundColor: const Color(0xFFF7F7F7),
|
||||||
|
body: CustomScrollView(
|
||||||
|
physics: const BouncingScrollPhysics(),
|
||||||
|
slivers: [
|
||||||
|
SliverAppBar(
|
||||||
|
backgroundColor: const Color(0xFF1677FF),
|
||||||
|
pinned: true,
|
||||||
|
centerTitle: true,
|
||||||
|
elevation: 0,
|
||||||
|
title: const Text(
|
||||||
|
"设备数据监控",
|
||||||
|
style: TextStyle(color: Colors.white, fontSize: 18, fontWeight: FontWeight.bold),
|
||||||
|
),
|
||||||
|
leading: IconButton(
|
||||||
|
icon: const Icon(Icons.arrow_back, color: Colors.white),
|
||||||
|
onPressed: () => Navigator.pop(context),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
// 顶部状态信息
|
||||||
|
BlocBuilder<DeviceStatusBloc, DeviceStatusState>(
|
||||||
|
builder: (context, state) {
|
||||||
|
String qual = '--';
|
||||||
|
String satelliteCnt = '--';
|
||||||
|
String headingStatus = "--";
|
||||||
|
|
||||||
|
if (state is DeviceStatusUpdated) {
|
||||||
|
headingStatus = state.status.headingStatus == 0 ? '未初始化' : '已初始化';
|
||||||
|
int qualValue = 0;
|
||||||
|
try {
|
||||||
|
qualValue = int.parse(state.status.qual.toString());
|
||||||
|
} catch (e) {
|
||||||
|
qualValue = 0;
|
||||||
|
}
|
||||||
|
qual = _parseLocationQuality(qualValue);
|
||||||
|
satelliteCnt = state.status.satelliteCnt.toString();
|
||||||
|
} else if (state is DeviceStatusError) {
|
||||||
|
qual = '-';
|
||||||
|
satelliteCnt = '-';
|
||||||
|
headingStatus = '-';
|
||||||
|
}
|
||||||
|
|
||||||
|
return SliverToBoxAdapter(
|
||||||
|
child: Container(
|
||||||
|
color: Colors.white,
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
flex: 3,
|
||||||
|
child: Text("航向角状态:$headingStatus", style: const TextStyle(fontSize: 12), maxLines: 1, overflow: TextOverflow.ellipsis),
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
flex: 4,
|
||||||
|
child: Text(
|
||||||
|
"定位质量:$qual",
|
||||||
|
style: const TextStyle(fontSize: 12),
|
||||||
|
maxLines: 1,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
flex: 2,
|
||||||
|
child: Text(
|
||||||
|
"卫星数:$satelliteCnt",
|
||||||
|
style: const TextStyle(fontSize: 12),
|
||||||
|
maxLines: 1,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
textAlign: TextAlign.right,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
|
||||||
|
// 切换选项卡
|
||||||
|
SliverToBoxAdapter(
|
||||||
|
child: Container(
|
||||||
|
color: Colors.white,
|
||||||
|
margin: const EdgeInsets.only(top: 8),
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
GestureDetector(
|
||||||
|
onTap: () => setState(() => _isCardView = true),
|
||||||
|
child: _buildTab("卡片", isActive: _isCardView),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 24),
|
||||||
|
GestureDetector(
|
||||||
|
onTap: () => setState(() => _isCardView = false),
|
||||||
|
child: _buildTab("图表", isActive: !_isCardView),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
ElevatedButton(
|
||||||
|
style: ElevatedButton.styleFrom(
|
||||||
|
backgroundColor: const Color(0xFF1677FF),
|
||||||
|
foregroundColor: Colors.white,
|
||||||
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(4)),
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||||
|
),
|
||||||
|
onPressed: _refreshDeviceData,
|
||||||
|
child: const Text("刷新数据", style: TextStyle(fontSize: 14)),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
// 主要内容区域(修复Sliver嵌套问题)
|
||||||
|
SliverToBoxAdapter(
|
||||||
|
child: BlocBuilder<DeviceStatusBloc, DeviceStatusState>(
|
||||||
|
builder: (context, state) {
|
||||||
|
// 追加图表数据
|
||||||
|
if (state is DeviceStatusUpdated) {
|
||||||
|
_appendChartData(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Container(
|
||||||
|
margin: const EdgeInsets.all(16),
|
||||||
|
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(8)),
|
||||||
|
child: _isCardView ? _buildCardContentView(state) : _buildChartContentView(state),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
20
pubspec.lock
20
pubspec.lock
@@ -348,10 +348,10 @@ packages:
|
|||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: fl_chart
|
name: fl_chart
|
||||||
sha256: d0f0d49112f2f4b192481c16d05b6418bd7820e021e265a3c22db98acf7ed7fb
|
sha256: "00b74ae680df6b1135bdbea00a7d1fc072a9180b7c3f3702e4b19a9943f5ed7d"
|
||||||
url: "https://pub.flutter-io.cn"
|
url: "https://pub.flutter-io.cn"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.68.0"
|
version: "0.66.2"
|
||||||
flutter:
|
flutter:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description: flutter
|
description: flutter
|
||||||
@@ -1188,6 +1188,22 @@ packages:
|
|||||||
url: "https://pub.flutter-io.cn"
|
url: "https://pub.flutter-io.cn"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.4.1"
|
version: "1.4.1"
|
||||||
|
syncfusion_flutter_core:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: syncfusion_flutter_core
|
||||||
|
sha256: "080c4a57f12cb03869c863f6b33fb170ce9653ac741281f11ff8e067dc96fe99"
|
||||||
|
url: "https://pub.flutter-io.cn"
|
||||||
|
source: hosted
|
||||||
|
version: "32.2.8"
|
||||||
|
syncfusion_flutter_gauges:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: syncfusion_flutter_gauges
|
||||||
|
sha256: "11ec00997cf37c5b02c00689b7083875f0f77561b43fbe760997eda30a321a99"
|
||||||
|
url: "https://pub.flutter-io.cn"
|
||||||
|
source: hosted
|
||||||
|
version: "32.2.8"
|
||||||
synchronized:
|
synchronized:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|||||||
@@ -118,7 +118,8 @@ dependencies:
|
|||||||
# 高德地图需要的权限
|
# 高德地图需要的权限
|
||||||
permission_handler: ^12.0.1
|
permission_handler: ^12.0.1
|
||||||
# 图表
|
# 图表
|
||||||
fl_chart: ^0.68.0
|
fl_chart: ^0.66.0
|
||||||
|
syncfusion_flutter_gauges: ^32.2.8
|
||||||
|
|
||||||
#qr_code_scanner: ^1.0.1 # 用于扫描二维码
|
#qr_code_scanner: ^1.0.1 # 用于扫描二维码
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user