136 lines
3.9 KiB
Dart
136 lines
3.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_svg/flutter_svg.dart';
|
|
|
|
/// 电池信息面板(电压 + 温度 + 极值)
|
|
class BatteryInfoPanel extends StatelessWidget {
|
|
final double batteryVolt;
|
|
final double batteryTemp;
|
|
final double maxVolt;
|
|
final double minVolt;
|
|
final double maxTemp;
|
|
final double minTemp;
|
|
|
|
const BatteryInfoPanel({
|
|
super.key,
|
|
required this.batteryVolt,
|
|
required this.batteryTemp,
|
|
required this.maxVolt,
|
|
required this.minVolt,
|
|
required this.maxTemp,
|
|
required this.minTemp,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
_buildInfoItem(
|
|
_buildIcon('voltage'),
|
|
'电压',
|
|
'${batteryVolt.toStringAsFixed(3)}V',
|
|
),
|
|
const SizedBox(height: 8),
|
|
Row(
|
|
children: [
|
|
Text(
|
|
'↑ ${maxVolt.toStringAsFixed(3)}V',
|
|
style: const TextStyle(
|
|
color: Colors.red,
|
|
fontSize: 14,
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
),
|
|
const SizedBox(width: 12),
|
|
Text(
|
|
'↓ ${minVolt.toStringAsFixed(3)}V',
|
|
style: const TextStyle(
|
|
color: Colors.blue,
|
|
fontSize: 14,
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
_buildInfoItem(
|
|
_buildIcon('temperature'),
|
|
'温度',
|
|
'${batteryTemp.toStringAsFixed(0)}°C',
|
|
),
|
|
const SizedBox(height: 8),
|
|
Row(
|
|
children: [
|
|
Text(
|
|
'↑ ${maxTemp.toStringAsFixed(0)}°C',
|
|
style: const TextStyle(
|
|
color: Colors.red,
|
|
fontSize: 14,
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
),
|
|
const SizedBox(width: 12),
|
|
Text(
|
|
'↓ ${minTemp.toStringAsFixed(0)}°C',
|
|
style: const TextStyle(
|
|
color: Colors.blue,
|
|
fontSize: 14,
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _buildIcon(String type) {
|
|
switch (type) {
|
|
case 'voltage':
|
|
return SvgPicture.asset(
|
|
'assets/icons/si--lightning-fill.svg',
|
|
width: 18,
|
|
height: 18,
|
|
colorFilter: const ColorFilter.mode(Colors.grey, BlendMode.srcIn),
|
|
);
|
|
case 'temperature':
|
|
return SvgPicture.asset(
|
|
'assets/icons/mdi--temperature.svg',
|
|
width: 18,
|
|
height: 18,
|
|
colorFilter: const ColorFilter.mode(Colors.grey, BlendMode.srcIn),
|
|
);
|
|
default:
|
|
return const Icon(Icons.help_outline, size: 18, color: Colors.grey);
|
|
}
|
|
}
|
|
|
|
Widget _buildInfoItem(Widget icon, String label, String value) {
|
|
return Row(
|
|
children: [
|
|
icon,
|
|
const SizedBox(width: 6),
|
|
Text(label, style: const TextStyle(fontSize: 14, color: Colors.grey)),
|
|
const SizedBox(width: 6),
|
|
Text(
|
|
value,
|
|
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w500),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|