- Extract reusable widgets (chat composer/send pipeline, message bubble frame, reaction chips, path map scaffold, radio settings dialog, translation settings section, map POI clusters, nav tiles, etc.) and slim down the screens that used them - Map: hide/remove markers with restore, confirm before setting node location, POI clustering, semantics labels - Map cache: cancellable downloads and a bulk tile limit - Repeater: unsaved-changes guard, CLI search/copy/share transcript, framed-command debug preview, disconnected banner - Confirm before clearing chats and debug logs - Keep cached unread totals in sync on per-contact/channel updates - Move remaining hardcoded strings into l10n and translate the 98 new keys into all 17 non-English locales
97 lines
2.7 KiB
Dart
97 lines
2.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import '../connector/meshcore_connector.dart';
|
|
import '../theme/mesh_theme.dart';
|
|
|
|
class BatteryUi {
|
|
final IconData icon;
|
|
final Color? color;
|
|
const BatteryUi(this.icon, this.color);
|
|
}
|
|
|
|
BatteryUi batteryUiForPercent(int? percent) {
|
|
if (percent == null) {
|
|
return const BatteryUi(Icons.battery_unknown, null);
|
|
}
|
|
|
|
final p = percent.clamp(0, 100);
|
|
|
|
return switch (p) {
|
|
<= 5 => const BatteryUi(Icons.battery_alert, MeshPalette.alert),
|
|
<= 15 => const BatteryUi(Icons.battery_0_bar, MeshPalette.alert),
|
|
<= 30 => const BatteryUi(Icons.battery_1_bar, MeshPalette.warn),
|
|
<= 45 => const BatteryUi(Icons.battery_2_bar, MeshPalette.warn),
|
|
<= 60 => const BatteryUi(Icons.battery_3_bar, null),
|
|
<= 80 => const BatteryUi(Icons.battery_5_bar, null),
|
|
_ => const BatteryUi(Icons.battery_full, MeshPalette.signal),
|
|
};
|
|
}
|
|
|
|
class BatteryIndicator extends StatefulWidget {
|
|
final MeshCoreConnector connector;
|
|
|
|
const BatteryIndicator({super.key, required this.connector});
|
|
|
|
@override
|
|
State<BatteryIndicator> createState() => _BatteryIndicatorState();
|
|
}
|
|
|
|
class _BatteryIndicatorState extends State<BatteryIndicator> {
|
|
bool _showBatteryVoltage = false;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final percent = widget.connector.batteryPercent;
|
|
final millivolts = widget.connector.batteryMillivolts;
|
|
|
|
if (millivolts == null) {
|
|
return const SizedBox.shrink();
|
|
}
|
|
|
|
final String displayText;
|
|
if (_showBatteryVoltage) {
|
|
displayText = '${(millivolts / 1000.0).toStringAsFixed(2)}V';
|
|
} else {
|
|
displayText = percent != null ? '$percent%' : '—';
|
|
}
|
|
|
|
final batteryUi = batteryUiForPercent(percent);
|
|
|
|
return InkWell(
|
|
onTap: () {
|
|
setState(() {
|
|
_showBatteryVoltage = !_showBatteryVoltage;
|
|
});
|
|
},
|
|
borderRadius: BorderRadius.circular(8),
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 8),
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Icon(batteryUi.icon, size: 18, color: batteryUi.color),
|
|
const SizedBox(height: 2),
|
|
Flexible(
|
|
child: Text(
|
|
displayText,
|
|
style: MeshTheme.mono(
|
|
fontSize: 12,
|
|
fontWeight: FontWeight.w600,
|
|
color: batteryUi.color,
|
|
),
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|