新批次的夜间模式适配代码
This commit is contained in:
@@ -24,9 +24,12 @@ class BatteryInfoPanel extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
final bool isVoltageAbnormal =
|
||||
abnormalType == DataAbnormalType.voltageAbnormal;
|
||||
final Color voltColor = isVoltageAbnormal ? Colors.red : Colors.black;
|
||||
|
||||
final Color defaultTextColor = Theme.of(context).colorScheme.onSurface;
|
||||
final Color voltColor = isVoltageAbnormal ? Colors.red : defaultTextColor;
|
||||
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
@@ -36,7 +39,8 @@ class BatteryInfoPanel extends StatelessWidget {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildInfoItem(
|
||||
_buildIcon('voltage'),
|
||||
context, // 🆕
|
||||
_buildIcon('voltage', isDark),
|
||||
'电压',
|
||||
'${batteryVolt.toStringAsFixed(3)}V',
|
||||
textColor: voltColor,
|
||||
@@ -50,12 +54,14 @@ class BatteryInfoPanel extends StatelessWidget {
|
||||
fontFamily: 'Flyme',
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Colors.red,
|
||||
color: isVoltageAbnormal
|
||||
? Colors.red
|
||||
: defaultTextColor,
|
||||
),
|
||||
children: [
|
||||
const TextSpan(
|
||||
TextSpan(
|
||||
text: '↑ ',
|
||||
style: TextStyle(
|
||||
style: const TextStyle(
|
||||
fontFamily: 'HarmonyOS_Sans_SC',
|
||||
color: Colors.red,
|
||||
),
|
||||
@@ -76,12 +82,14 @@ class BatteryInfoPanel extends StatelessWidget {
|
||||
fontFamily: 'Flyme',
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Colors.blue,
|
||||
color: isVoltageAbnormal
|
||||
? Colors.red
|
||||
: defaultTextColor,
|
||||
),
|
||||
children: [
|
||||
const TextSpan(
|
||||
TextSpan(
|
||||
text: '↓ ',
|
||||
style: TextStyle(
|
||||
style: const TextStyle(
|
||||
fontFamily: 'HarmonyOS_Sans_SC',
|
||||
color: Colors.blue,
|
||||
),
|
||||
@@ -105,20 +113,22 @@ class BatteryInfoPanel extends StatelessWidget {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildInfoItem(
|
||||
_buildIcon('temperature'),
|
||||
context, // 🆕
|
||||
_buildIcon('temperature', isDark),
|
||||
'温度',
|
||||
'${batteryTemp.toStringAsFixed(0)}℃',
|
||||
textColor: defaultTextColor,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
children: [
|
||||
RichText(
|
||||
text: TextSpan(
|
||||
style: const TextStyle(
|
||||
style: TextStyle(
|
||||
fontFamily: 'Flyme',
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Colors.red,
|
||||
color: defaultTextColor,
|
||||
),
|
||||
children: [
|
||||
const TextSpan(
|
||||
@@ -135,11 +145,11 @@ class BatteryInfoPanel extends StatelessWidget {
|
||||
const SizedBox(width: 12),
|
||||
RichText(
|
||||
text: TextSpan(
|
||||
style: const TextStyle(
|
||||
style: TextStyle(
|
||||
fontFamily: 'Flyme',
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Colors.blue,
|
||||
color: defaultTextColor,
|
||||
),
|
||||
children: [
|
||||
const TextSpan(
|
||||
@@ -162,43 +172,46 @@ class BatteryInfoPanel extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildIcon(String type) {
|
||||
Widget _buildIcon(String type, bool isDark) {
|
||||
final color = isDark ? Colors.white54 : Colors.grey;
|
||||
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),
|
||||
colorFilter: ColorFilter.mode(color, BlendMode.srcIn),
|
||||
);
|
||||
case 'temperature':
|
||||
return SvgPicture.asset(
|
||||
'assets/icons/mdi--temperature.svg',
|
||||
width: 18,
|
||||
height: 18,
|
||||
colorFilter: const ColorFilter.mode(Colors.grey, BlendMode.srcIn),
|
||||
colorFilter: ColorFilter.mode(color, BlendMode.srcIn),
|
||||
);
|
||||
default:
|
||||
return const Icon(Icons.help_outline, size: 18, color: Colors.grey);
|
||||
return Icon(Icons.help_outline, size: 18, color: color);
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildInfoItem(
|
||||
BuildContext context, // 🆕
|
||||
Widget icon,
|
||||
String label,
|
||||
String value, {
|
||||
Color textColor = Colors.black,
|
||||
}) {
|
||||
final labelColor = Theme.of(context).colorScheme.onSurface.withOpacity(0.7);
|
||||
return Row(
|
||||
children: [
|
||||
icon,
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
label,
|
||||
style: const TextStyle(
|
||||
style: TextStyle(
|
||||
fontFamily: 'HarmonyOS_Sans_SC',
|
||||
fontSize: 14,
|
||||
color: Colors.grey,
|
||||
color: labelColor,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
|
||||
Reference in New Issue
Block a user