Fix annoying plist reset

This commit is contained in:
Janez T
2026-03-07 20:00:32 +01:00
parent 1867f815d2
commit 5966ddfbc1
7 changed files with 633 additions and 286 deletions

View File

@@ -489,7 +489,7 @@
buildSettings = { buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = 98; CURRENT_PROJECT_VERSION = 100;
DEVELOPMENT_TEAM = JND55328G8; DEVELOPMENT_TEAM = JND55328G8;
ENABLE_BITCODE = NO; ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist; INFOPLIST_FILE = Runner/Info.plist;
@@ -511,7 +511,7 @@
buildSettings = { buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)"; BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 98; CURRENT_PROJECT_VERSION = 100;
DEVELOPMENT_TEAM = JND55328G8; DEVELOPMENT_TEAM = JND55328G8;
GENERATE_INFOPLIST_FILE = YES; GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 1.0; MARKETING_VERSION = 1.0;
@@ -530,7 +530,7 @@
buildSettings = { buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)"; BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 98; CURRENT_PROJECT_VERSION = 100;
DEVELOPMENT_TEAM = JND55328G8; DEVELOPMENT_TEAM = JND55328G8;
GENERATE_INFOPLIST_FILE = YES; GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 1.0; MARKETING_VERSION = 1.0;
@@ -547,7 +547,7 @@
buildSettings = { buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)"; BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 98; CURRENT_PROJECT_VERSION = 100;
DEVELOPMENT_TEAM = JND55328G8; DEVELOPMENT_TEAM = JND55328G8;
GENERATE_INFOPLIST_FILE = YES; GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 1.0; MARKETING_VERSION = 1.0;
@@ -679,7 +679,7 @@
buildSettings = { buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = 98; CURRENT_PROJECT_VERSION = 100;
DEVELOPMENT_TEAM = JND55328G8; DEVELOPMENT_TEAM = JND55328G8;
ENABLE_BITCODE = NO; ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist; INFOPLIST_FILE = Runner/Info.plist;
@@ -702,7 +702,7 @@
buildSettings = { buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = 98; CURRENT_PROJECT_VERSION = 100;
DEVELOPMENT_TEAM = JND55328G8; DEVELOPMENT_TEAM = JND55328G8;
ENABLE_BITCODE = NO; ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist; INFOPLIST_FILE = Runner/Info.plist;

View File

@@ -43,7 +43,7 @@
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>98</string> <string>100</string>
<key>LSRequiresIPhoneOS</key> <key>LSRequiresIPhoneOS</key>
<true/> <true/>
<key>NSBluetoothAlwaysUsageDescription</key> <key>NSBluetoothAlwaysUsageDescription</key>

View File

@@ -5,22 +5,17 @@
<testcase classname="fastlane.lanes" name="0: default_platform" time="0.001195"> <testcase classname="fastlane.lanes" name="0: default_platform" time="0.000199">
</testcase> </testcase>
<testcase classname="fastlane.lanes" name="1: increment_build_number" time="0.410921"> <testcase classname="fastlane.lanes" name="1: increment_build_number" time="0.436347">
</testcase> </testcase>
<testcase classname="fastlane.lanes" name="2: build_app" time="97.264031"> <testcase classname="fastlane.lanes" name="2: build_app" time="49.579697">
</testcase>
<testcase classname="fastlane.lanes" name="3: upload_to_app_store" time="11727.562963">
</testcase> </testcase>

View File

@@ -416,19 +416,20 @@ class ContactsProvider with ChangeNotifier {
final previousTelemetry = contact.telemetry; final previousTelemetry = contact.telemetry;
// Keep last valid GPS whenever current telemetry does not provide a final mergedTelemetry = _mergeTelemetryForContact(
// valid GPS fix. existingTelemetry: previousTelemetry,
if (_shouldRetainLastValidGps(previousTelemetry, telemetry.gpsLocation)) { incomingTelemetry: telemetry,
debugPrint( );
' ⚠️ Retaining last valid GPS. Incoming telemetry GPS is invalid/missing: $incomingGps', if (mergedTelemetry != null) {
); if (_shouldRetainLastValidGps(
final mergedTelemetry = _mergeTelemetryForContact( previousTelemetry,
existingTelemetry: previousTelemetry, telemetry.gpsLocation,
incomingTelemetry: telemetry, )) {
); debugPrint(
if (mergedTelemetry != null) { ' ⚠️ Retaining last valid GPS. Incoming telemetry GPS is invalid/missing: $incomingGps',
telemetry = mergedTelemetry; );
} }
telemetry = mergedTelemetry;
} }
// Update contact with new telemetry AND last seen time // Update contact with new telemetry AND last seen time
@@ -504,24 +505,28 @@ class ContactsProvider with ChangeNotifier {
} }
final incomingGps = _getValidGpsOrNull(incomingTelemetry.gpsLocation); final incomingGps = _getValidGpsOrNull(incomingTelemetry.gpsLocation);
if (incomingGps != null) {
return incomingTelemetry;
}
final previousGps = _getValidGpsOrNull(existingTelemetry?.gpsLocation); final previousGps = _getValidGpsOrNull(existingTelemetry?.gpsLocation);
if (previousGps == null) { final mergedExtraSensorData = <String, dynamic>{
return incomingTelemetry; ...?existingTelemetry?.extraSensorData,
} ...?incomingTelemetry.extraSensorData,
};
return ContactTelemetry( return ContactTelemetry(
gpsLocation: previousGps, gpsLocation: incomingGps ?? previousGps,
batteryPercentage: incomingTelemetry.batteryPercentage, batteryPercentage:
batteryMilliVolts: incomingTelemetry.batteryMilliVolts, incomingTelemetry.batteryPercentage ??
temperature: incomingTelemetry.temperature, existingTelemetry?.batteryPercentage,
batteryMilliVolts:
incomingTelemetry.batteryMilliVolts ??
existingTelemetry?.batteryMilliVolts,
temperature:
incomingTelemetry.temperature ?? existingTelemetry?.temperature,
timestamp: incomingTelemetry.timestamp, timestamp: incomingTelemetry.timestamp,
humidity: incomingTelemetry.humidity, humidity: incomingTelemetry.humidity ?? existingTelemetry?.humidity,
pressure: incomingTelemetry.pressure, pressure: incomingTelemetry.pressure ?? existingTelemetry?.pressure,
extraSensorData: incomingTelemetry.extraSensorData, extraSensorData: mergedExtraSensorData.isEmpty
? null
: mergedExtraSensorData,
); );
} }

View File

@@ -10,36 +10,26 @@ import 'contacts_provider.dart';
enum SensorRefreshState { idle, refreshing, success, timeout, unavailable } enum SensorRefreshState { idle, refreshing, success, timeout, unavailable }
enum SensorMetric {
lastSeen,
voltage,
battery,
temperature,
humidity,
pressure,
gps,
updated,
}
class SensorsProvider with ChangeNotifier { class SensorsProvider with ChangeNotifier {
static const String _watchedSensorsKey = 'watched_sensor_keys'; static const String _watchedSensorsKey = 'watched_sensor_keys';
static const String _visibleSensorMetricsKey = 'visible_sensor_metrics'; static const String _visibleSensorMetricsKey = 'visible_sensor_metrics';
static const Set<SensorMetric> _defaultVisibleMetrics = <SensorMetric>{ static const String _fieldSpanKey = 'sensor_field_spans';
SensorMetric.lastSeen, static const Set<String> _defaultVisibleFields = <String>{
SensorMetric.voltage, 'voltage',
SensorMetric.battery, 'battery',
SensorMetric.temperature, 'temperature',
SensorMetric.humidity, 'humidity',
SensorMetric.pressure, 'pressure',
SensorMetric.gps, 'gps',
SensorMetric.updated,
}; };
final List<String> _watchedSensorKeys = <String>[]; final List<String> _watchedSensorKeys = <String>[];
final Map<String, SensorRefreshState> _refreshStates = final Map<String, SensorRefreshState> _refreshStates =
<String, SensorRefreshState>{}; <String, SensorRefreshState>{};
final Map<String, Set<SensorMetric>> _visibleMetricsBySensor = final Map<String, Set<String>> _visibleFieldsBySensor =
<String, Set<SensorMetric>>{}; <String, Set<String>>{};
final Map<String, Map<String, int>> _fieldSpansBySensor =
<String, Map<String, int>>{};
bool _isLoaded = false; bool _isLoaded = false;
bool _isRefreshingAll = false; bool _isRefreshingAll = false;
@@ -59,25 +49,33 @@ class SensorsProvider with ChangeNotifier {
final prefs = await SharedPreferences.getInstance(); final prefs = await SharedPreferences.getInstance();
final stored = prefs.getStringList(_watchedSensorsKey) ?? <String>[]; final stored = prefs.getStringList(_watchedSensorsKey) ?? <String>[];
final storedMetricsJson = prefs.getString(_visibleSensorMetricsKey); final storedMetricsJson = prefs.getString(_visibleSensorMetricsKey);
final storedSpansJson = prefs.getString(_fieldSpanKey);
_watchedSensorKeys _watchedSensorKeys
..clear() ..clear()
..addAll(stored); ..addAll(stored);
_visibleMetricsBySensor.clear(); _visibleFieldsBySensor.clear();
_fieldSpansBySensor.clear();
if (storedMetricsJson != null && storedMetricsJson.isNotEmpty) { if (storedMetricsJson != null && storedMetricsJson.isNotEmpty) {
final decoded = jsonDecode(storedMetricsJson) as Map<String, dynamic>; final decoded = jsonDecode(storedMetricsJson) as Map<String, dynamic>;
for (final entry in decoded.entries) { for (final entry in decoded.entries) {
final metricNames = (entry.value as List<dynamic>).cast<String>(); _visibleFieldsBySensor[entry.key] = (entry.value as List<dynamic>)
_visibleMetricsBySensor[entry.key] = metricNames .cast<String>()
.map(_metricFromName)
.whereType<SensorMetric>()
.toSet(); .toSet();
} }
} }
if (storedSpansJson != null && storedSpansJson.isNotEmpty) {
final decoded = jsonDecode(storedSpansJson) as Map<String, dynamic>;
for (final entry in decoded.entries) {
_fieldSpansBySensor[entry.key] = (entry.value as Map<String, dynamic>)
.map((key, value) => MapEntry(key, value as int));
}
}
for (final key in _watchedSensorKeys) { for (final key in _watchedSensorKeys) {
_visibleMetricsBySensor.putIfAbsent( _visibleFieldsBySensor.putIfAbsent(
key, key,
() => Set<SensorMetric>.from(_defaultVisibleMetrics), () => Set<String>.from(_defaultVisibleFields),
); );
_fieldSpansBySensor.putIfAbsent(key, () => <String, int>{});
} }
} catch (e) { } catch (e) {
debugPrint('Error loading watched sensors: $e'); debugPrint('Error loading watched sensors: $e');
@@ -100,8 +98,8 @@ class SensorsProvider with ChangeNotifier {
try { try {
final prefs = await SharedPreferences.getInstance(); final prefs = await SharedPreferences.getInstance();
final encoded = <String, List<String>>{}; final encoded = <String, List<String>>{};
for (final entry in _visibleMetricsBySensor.entries) { for (final entry in _visibleFieldsBySensor.entries) {
encoded[entry.key] = entry.value.map((metric) => metric.name).toList(); encoded[entry.key] = entry.value.toList();
} }
await prefs.setString(_visibleSensorMetricsKey, jsonEncode(encoded)); await prefs.setString(_visibleSensorMetricsKey, jsonEncode(encoded));
} catch (e) { } catch (e) {
@@ -109,35 +107,63 @@ class SensorsProvider with ChangeNotifier {
} }
} }
Set<SensorMetric> visibleMetricsFor(String publicKeyHex) => Future<void> _persistFieldSpans() async {
Set<SensorMetric>.unmodifiable( try {
_visibleMetricsBySensor[publicKeyHex] ?? _defaultVisibleMetrics, final prefs = await SharedPreferences.getInstance();
); await prefs.setString(_fieldSpanKey, jsonEncode(_fieldSpansBySensor));
} catch (e) {
debugPrint('Error saving sensor field spans: $e');
}
}
bool showsMetric(String publicKeyHex, SensorMetric metric) => Set<String> visibleFieldsFor(String publicKeyHex) => Set<String>.unmodifiable(
visibleMetricsFor(publicKeyHex).contains(metric); _visibleFieldsBySensor[publicKeyHex] ?? _defaultVisibleFields,
);
bool showsField(String publicKeyHex, String fieldKey) =>
visibleFieldsFor(publicKeyHex).contains(fieldKey);
int fieldSpanFor(String publicKeyHex, String fieldKey) {
final sensorSpans = _fieldSpansBySensor[publicKeyHex];
final span = sensorSpans?[fieldKey] ?? 1;
return span == 2 ? 2 : 1;
}
Future<void> toggleMetric( Future<void> toggleMetric(
String publicKeyHex, String publicKeyHex,
SensorMetric metric, String fieldKey,
bool visible, bool visible,
) async { ) async {
final visibleMetrics = _visibleMetricsBySensor.putIfAbsent( final visibleFields = _visibleFieldsBySensor.putIfAbsent(
publicKeyHex, publicKeyHex,
() => Set<SensorMetric>.from(_defaultVisibleMetrics), () => Set<String>.from(_defaultVisibleFields),
); );
if (visible) { if (visible) {
visibleMetrics.add(metric); visibleFields.add(fieldKey);
} else { } else {
if (visibleMetrics.length == 1 && visibleMetrics.contains(metric)) { if (visibleFields.length == 1 && visibleFields.contains(fieldKey)) {
return; return;
} }
visibleMetrics.remove(metric); visibleFields.remove(fieldKey);
} }
await _persistVisibleMetrics(); await _persistVisibleMetrics();
notifyListeners(); notifyListeners();
} }
Future<void> setFieldSpan(
String publicKeyHex,
String fieldKey,
int span,
) async {
final sensorSpans = _fieldSpansBySensor.putIfAbsent(
publicKeyHex,
() => <String, int>{},
);
sensorSpans[fieldKey] = span == 2 ? 2 : 1;
await _persistFieldSpans();
notifyListeners();
}
bool isWatched(String publicKeyHex) => bool isWatched(String publicKeyHex) =>
_watchedSensorKeys.contains(publicKeyHex); _watchedSensorKeys.contains(publicKeyHex);
@@ -151,19 +177,23 @@ class SensorsProvider with ChangeNotifier {
_watchedSensorKeys.add(contact.publicKeyHex); _watchedSensorKeys.add(contact.publicKeyHex);
await _persistWatchedSensors(); await _persistWatchedSensors();
_visibleMetricsBySensor[contact.publicKeyHex] = Set<SensorMetric>.from( _visibleFieldsBySensor[contact.publicKeyHex] = Set<String>.from(
_defaultVisibleMetrics, _defaultVisibleFields,
); );
_fieldSpansBySensor[contact.publicKeyHex] = <String, int>{'gps': 2};
await _persistVisibleMetrics(); await _persistVisibleMetrics();
await _persistFieldSpans();
notifyListeners(); notifyListeners();
} }
Future<void> removeSensor(String publicKeyHex) async { Future<void> removeSensor(String publicKeyHex) async {
_watchedSensorKeys.remove(publicKeyHex); _watchedSensorKeys.remove(publicKeyHex);
_refreshStates.remove(publicKeyHex); _refreshStates.remove(publicKeyHex);
_visibleMetricsBySensor.remove(publicKeyHex); _visibleFieldsBySensor.remove(publicKeyHex);
_fieldSpansBySensor.remove(publicKeyHex);
await _persistWatchedSensors(); await _persistWatchedSensors();
await _persistVisibleMetrics(); await _persistVisibleMetrics();
await _persistFieldSpans();
notifyListeners(); notifyListeners();
} }
@@ -221,13 +251,4 @@ class SensorsProvider with ChangeNotifier {
notifyListeners(); notifyListeners();
} }
} }
SensorMetric? _metricFromName(String name) {
for (final metric in SensorMetric.values) {
if (metric.name == name) {
return metric;
}
}
return null;
}
} }

View File

@@ -1,4 +1,6 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart' as flutter_map;
import 'package:latlong2/latlong.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import '../l10n/app_localizations.dart'; import '../l10n/app_localizations.dart';
@@ -6,6 +8,7 @@ import '../models/contact.dart';
import '../providers/connection_provider.dart'; import '../providers/connection_provider.dart';
import '../providers/contacts_provider.dart'; import '../providers/contacts_provider.dart';
import '../providers/sensors_provider.dart'; import '../providers/sensors_provider.dart';
import '../utils/location_formats.dart';
class SensorsTab extends StatelessWidget { class SensorsTab extends StatelessWidget {
const SensorsTab({super.key}); const SensorsTab({super.key});
@@ -83,15 +86,15 @@ class SensorsTab extends StatelessWidget {
Future<void> _showMetricSelector( Future<void> _showMetricSelector(
BuildContext context, BuildContext context,
String publicKeyHex, String publicKeyHex,
Contact? contact,
) async { ) async {
await showModalBottomSheet<void>( await showModalBottomSheet<void>(
context: context, context: context,
showDragHandle: true, showDragHandle: true,
builder: (sheetContext) => Consumer<SensorsProvider>( builder: (sheetContext) => Consumer<SensorsProvider>(
builder: (context, sensorsProvider, child) { builder: (context, sensorsProvider, child) {
final visibleMetrics = sensorsProvider.visibleMetricsFor( final visibleFields = sensorsProvider.visibleFieldsFor(publicKeyHex);
publicKeyHex, final options = _fieldOptionsFor(contact);
);
return SafeArea( return SafeArea(
child: ListView( child: ListView(
shrinkWrap: true, shrinkWrap: true,
@@ -107,24 +110,48 @@ class SensorsTab extends StatelessWidget {
style: Theme.of(context).textTheme.bodyMedium, style: Theme.of(context).textTheme.bodyMedium,
), ),
const SizedBox(height: 20), const SizedBox(height: 20),
Wrap( ...options.map((option) {
spacing: 10, final visible = visibleFields.contains(option.key);
runSpacing: 10, final span = sensorsProvider.fieldSpanFor(
children: SensorMetric.values.map((metric) { publicKeyHex,
final visible = visibleMetrics.contains(metric); option.key,
return FilterChip( );
selected: visible, return Padding(
label: Text(_metricLabel(metric)), padding: const EdgeInsets.only(bottom: 12),
onSelected: (value) { child: Row(
sensorsProvider.toggleMetric( children: [
publicKeyHex, Expanded(
metric, child: FilterChip(
value, selected: visible,
); label: Text(option.label),
}, onSelected: (value) {
); sensorsProvider.toggleMetric(
}).toList(), publicKeyHex,
), option.key,
value,
);
},
),
),
const SizedBox(width: 10),
SegmentedButton<int>(
segments: const [
ButtonSegment<int>(value: 1, label: Text('1x')),
ButtonSegment<int>(value: 2, label: Text('2x')),
],
selected: <int>{span},
onSelectionChanged: (selection) {
sensorsProvider.setFieldSpan(
publicKeyHex,
option.key,
selection.first,
);
},
),
],
),
);
}),
], ],
), ),
); );
@@ -170,11 +197,18 @@ class SensorsTab extends StatelessWidget {
return _SensorCard( return _SensorCard(
contact: contact, contact: contact,
state: sensorsProvider.stateFor(key), state: sensorsProvider.stateFor(key),
visibleMetrics: sensorsProvider.visibleMetricsFor(key), visibleFields: sensorsProvider.visibleFieldsFor(key),
fieldSpans: {
for (final field in sensorsProvider.visibleFieldsFor(
key,
))
field: sensorsProvider.fieldSpanFor(key, field),
},
onRemove: () async { onRemove: () async {
await sensorsProvider.removeSensor(key); await sensorsProvider.removeSensor(key);
}, },
onCustomize: () => _showMetricSelector(context, key), onCustomize: () =>
_showMetricSelector(context, key, contact),
); );
}), }),
], ],
@@ -265,14 +299,16 @@ class _EmptySensorsState extends StatelessWidget {
class _SensorCard extends StatelessWidget { class _SensorCard extends StatelessWidget {
final Contact? contact; final Contact? contact;
final SensorRefreshState state; final SensorRefreshState state;
final Set<SensorMetric> visibleMetrics; final Set<String> visibleFields;
final Map<String, int> fieldSpans;
final Future<void> Function() onRemove; final Future<void> Function() onRemove;
final VoidCallback onCustomize; final VoidCallback onCustomize;
const _SensorCard({ const _SensorCard({
required this.contact, required this.contact,
required this.state, required this.state,
required this.visibleMetrics, required this.visibleFields,
required this.fieldSpans,
required this.onRemove, required this.onRemove,
required this.onCustomize, required this.onCustomize,
}); });
@@ -303,7 +339,7 @@ class _SensorCard extends StatelessWidget {
], ],
), ),
child: Padding( child: Padding(
padding: const EdgeInsets.all(18), padding: const EdgeInsets.all(12),
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
@@ -331,11 +367,36 @@ class _SensorCard extends StatelessWidget {
), ),
if (telemetry != null) ...[ if (telemetry != null) ...[
const SizedBox(height: 2), const SizedBox(height: 2),
Text( Wrap(
'${_formatTelemetryDateTime(telemetry.timestamp)}${_formatTelemetryTime(telemetry.timestamp)}', spacing: 6,
style: theme.textTheme.bodySmall?.copyWith( runSpacing: 4,
color: theme.colorScheme.onSurfaceVariant, crossAxisAlignment: WrapCrossAlignment.center,
), children: [
Text(
'${_formatTelemetryDateTime(telemetry.timestamp)}${_formatTelemetryTime(telemetry.timestamp)}',
style: theme.textTheme.bodySmall?.copyWith(
color: theme.colorScheme.onSurfaceVariant,
),
),
if (state == SensorRefreshState.refreshing)
const _InlineStateMeta(
label: 'Refreshing',
color: Color(0xFF266AC2),
spinning: true,
),
if (state == SensorRefreshState.success)
const _InlineStateMeta(
label: 'Updated',
color: Color(0xFF218B63),
icon: Icons.check_circle,
),
if (state == SensorRefreshState.unavailable)
const _InlineStateMeta(
label: 'Unavailable',
color: Color(0xFFB13B55),
icon: Icons.error_outline,
),
],
), ),
], ],
], ],
@@ -363,30 +424,6 @@ class _SensorCard extends StatelessWidget {
], ],
), ),
const SizedBox(height: 12), const SizedBox(height: 12),
if (((state != SensorRefreshState.idle &&
state != SensorRefreshState.timeout) ||
state == SensorRefreshState.unavailable) ||
(contact != null &&
visibleMetrics.contains(SensorMetric.lastSeen)))
Padding(
padding: const EdgeInsets.only(bottom: 12),
child: Wrap(
spacing: 10,
runSpacing: 10,
children: [
if (state != SensorRefreshState.idle &&
state != SensorRefreshState.timeout)
_StatusPill(state: state),
if (contact != null &&
visibleMetrics.contains(SensorMetric.lastSeen))
_InfoPill(
icon: Icons.schedule,
label:
'${l10n.lastSeen}: ${contact!.timeSinceLastSeen}',
),
],
),
),
if (contact == null) if (contact == null)
const Text( const Text(
'This node is no longer available in the contact list.', 'This node is no longer available in the contact list.',
@@ -398,12 +435,28 @@ class _SensorCard extends StatelessWidget {
'All fields are hidden. Use Visible fields to choose what to show.', 'All fields are hidden. Use Visible fields to choose what to show.',
) )
else else
Wrap( LayoutBuilder(
spacing: 12, builder: (context, constraints) {
runSpacing: 12, const spacing = 8.0;
children: metrics final compactWidth = (constraints.maxWidth - spacing) / 2;
.map((metric) => _MetricTile(data: metric))
.toList(), return Wrap(
spacing: spacing,
runSpacing: spacing,
children: metrics
.map(
(metric) => _MetricTile(
data: metric,
width:
(fieldSpans[metric.fieldKey] == 2 ||
metric.wide)
? constraints.maxWidth
: compactWidth,
),
)
.toList(),
);
},
), ),
], ],
), ),
@@ -418,10 +471,11 @@ class _SensorCard extends StatelessWidget {
) { ) {
final items = <_MetricCardData>[]; final items = <_MetricCardData>[];
if (visibleMetrics.contains(SensorMetric.voltage) && if (visibleFields.contains('voltage') &&
telemetry.batteryMilliVolts != null) { telemetry.batteryMilliVolts != null) {
items.add( items.add(
_MetricCardData( _MetricCardData(
fieldKey: 'voltage',
icon: Icons.bolt, icon: Icons.bolt,
label: l10n.voltage, label: l10n.voltage,
value: '${(telemetry.batteryMilliVolts! / 1000).toStringAsFixed(3)}V', value: '${(telemetry.batteryMilliVolts! / 1000).toStringAsFixed(3)}V',
@@ -429,10 +483,11 @@ class _SensorCard extends StatelessWidget {
), ),
); );
} }
if (visibleMetrics.contains(SensorMetric.battery) && if (visibleFields.contains('battery') &&
telemetry.batteryPercentage != null) { telemetry.batteryPercentage != null) {
items.add( items.add(
_MetricCardData( _MetricCardData(
fieldKey: 'battery',
icon: Icons.battery_5_bar, icon: Icons.battery_5_bar,
label: l10n.battery, label: l10n.battery,
value: '${telemetry.batteryPercentage!.toStringAsFixed(0)}%', value: '${telemetry.batteryPercentage!.toStringAsFixed(0)}%',
@@ -440,10 +495,11 @@ class _SensorCard extends StatelessWidget {
), ),
); );
} }
if (visibleMetrics.contains(SensorMetric.temperature) && if (visibleFields.contains('temperature') &&
telemetry.temperature != null) { telemetry.temperature != null) {
items.add( items.add(
_MetricCardData( _MetricCardData(
fieldKey: 'temperature',
icon: Icons.thermostat, icon: Icons.thermostat,
label: l10n.temperature, label: l10n.temperature,
value: '${telemetry.temperature!.toStringAsFixed(1)}°C', value: '${telemetry.temperature!.toStringAsFixed(1)}°C',
@@ -451,10 +507,10 @@ class _SensorCard extends StatelessWidget {
), ),
); );
} }
if (visibleMetrics.contains(SensorMetric.humidity) && if (visibleFields.contains('humidity') && telemetry.humidity != null) {
telemetry.humidity != null) {
items.add( items.add(
_MetricCardData( _MetricCardData(
fieldKey: 'humidity',
icon: Icons.water_drop, icon: Icons.water_drop,
label: l10n.humidity, label: l10n.humidity,
value: '${telemetry.humidity!.toStringAsFixed(1)}%', value: '${telemetry.humidity!.toStringAsFixed(1)}%',
@@ -462,10 +518,10 @@ class _SensorCard extends StatelessWidget {
), ),
); );
} }
if (visibleMetrics.contains(SensorMetric.pressure) && if (visibleFields.contains('pressure') && telemetry.pressure != null) {
telemetry.pressure != null) {
items.add( items.add(
_MetricCardData( _MetricCardData(
fieldKey: 'pressure',
icon: Icons.compress, icon: Icons.compress,
label: l10n.pressure, label: l10n.pressure,
value: '${telemetry.pressure!.toStringAsFixed(1)} hPa', value: '${telemetry.pressure!.toStringAsFixed(1)} hPa',
@@ -473,35 +529,38 @@ class _SensorCard extends StatelessWidget {
), ),
); );
} }
if (visibleMetrics.contains(SensorMetric.gps) && if (visibleFields.contains('gps') && telemetry.gpsLocation != null) {
telemetry.gpsLocation != null) {
items.add( items.add(
_MetricCardData( _MetricCardData(
fieldKey: 'gps',
icon: Icons.place, icon: Icons.place,
label: l10n.gpsTelemetry, label: l10n.gpsTelemetry,
value: value:
'${telemetry.gpsLocation!.latitude.toStringAsFixed(5)}, ${telemetry.gpsLocation!.longitude.toStringAsFixed(5)}', '${telemetry.gpsLocation!.latitude.toStringAsFixed(5)}, ${telemetry.gpsLocation!.longitude.toStringAsFixed(5)}',
accent: const Color(0xFFAA3F57), accent: const Color(0xFFAA3F57),
wide: true, wide: true,
), mapLocation: LatLng(
); telemetry.gpsLocation!.latitude,
} telemetry.gpsLocation!.longitude,
if (visibleMetrics.contains(SensorMetric.updated)) { ),
items.add( secondaryValue: formatPlusCode(
_MetricCardData( telemetry.gpsLocation!.latitude,
icon: Icons.update, telemetry.gpsLocation!.longitude,
label: l10n.updated, ),
value: _formatTelemetryTime(telemetry.timestamp),
accent: const Color(0xFF6C727F),
), ),
); );
} }
if (telemetry.extraSensorData != null) { if (telemetry.extraSensorData != null) {
for (final entry in telemetry.extraSensorData!.entries) { for (final entry in telemetry.extraSensorData!.entries) {
final fieldKey = _extraFieldKey(entry.key);
if (!visibleFields.contains(fieldKey)) {
continue;
}
items.add( items.add(
_MetricCardData( _MetricCardData(
fieldKey: fieldKey,
icon: Icons.sensors, icon: Icons.sensors,
label: entry.key, label: _formatExtraFieldLabel(entry.key),
value: '${entry.value}', value: '${entry.value}',
accent: const Color(0xFF3E657C), accent: const Color(0xFF3E657C),
), ),
@@ -531,81 +590,48 @@ class _SensorCard extends StatelessWidget {
} }
} }
class _StatusPill extends StatelessWidget { class _InlineStateMeta extends StatelessWidget {
final SensorRefreshState state;
const _StatusPill({required this.state});
@override
Widget build(BuildContext context) {
final (label, color, icon) = switch (state) {
SensorRefreshState.idle => (
'Idle',
const Color(0xFF5D7185),
Icons.sensors,
),
SensorRefreshState.refreshing => (
'Refreshing',
const Color(0xFF266AC2),
Icons.sync,
),
SensorRefreshState.success => (
'Updated',
const Color(0xFF218B63),
Icons.check_circle,
),
SensorRefreshState.timeout => (
'No response',
const Color(0xFFC17B1D),
Icons.schedule,
),
SensorRefreshState.unavailable => (
'Unavailable',
const Color(0xFFB13B55),
Icons.error_outline,
),
};
return _InfoPill(
icon: icon,
label: label,
foreground: color,
background: color.withValues(alpha: 0.10),
);
}
}
class _InfoPill extends StatelessWidget {
final IconData icon;
final String label; final String label;
final Color? foreground; final Color color;
final Color? background; final IconData? icon;
final bool spinning;
const _InfoPill({ const _InlineStateMeta({
required this.icon,
required this.label, required this.label,
this.foreground, required this.color,
this.background, this.icon,
this.spinning = false,
}); });
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final color = foreground ?? Theme.of(context).colorScheme.onSurfaceVariant;
return Container( return Container(
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 11), padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 3),
decoration: BoxDecoration( decoration: BoxDecoration(
color: color: color.withValues(alpha: 0.10),
background ?? Theme.of(context).colorScheme.surfaceContainerHighest, borderRadius: BorderRadius.circular(999),
borderRadius: BorderRadius.circular(18),
), ),
child: Row( child: Row(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
Icon(icon, size: 18, color: color), if (spinning)
const SizedBox(width: 8), SizedBox(
width: 11,
height: 11,
child: CircularProgressIndicator(
strokeWidth: 1.7,
valueColor: AlwaysStoppedAnimation<Color>(color),
),
)
else if (icon != null)
Icon(icon, size: 11, color: color),
const SizedBox(width: 4),
Text( Text(
label, label,
style: TextStyle(color: color, fontWeight: FontWeight.w600), style: Theme.of(context).textTheme.labelSmall?.copyWith(
color: color,
fontWeight: FontWeight.w700,
),
), ),
], ],
), ),
@@ -639,89 +665,389 @@ class _InlineAlertBadge extends StatelessWidget {
class _MetricTile extends StatelessWidget { class _MetricTile extends StatelessWidget {
final _MetricCardData data; final _MetricCardData data;
final double width;
const _MetricTile({required this.data}); const _MetricTile({required this.data, required this.width});
@override Future<void> _showExpandedMap(BuildContext context) async {
Widget build(BuildContext context) { final location = data.mapLocation;
final width = data.wide ? 320.0 : 168.0; if (location == null) return;
return Container( await showDialog<void>(
width: width, context: context,
padding: const EdgeInsets.all(14), builder: (dialogContext) {
decoration: BoxDecoration( return Dialog(
color: data.accent.withValues(alpha: 0.08), insetPadding: const EdgeInsets.all(16),
borderRadius: BorderRadius.circular(22), clipBehavior: Clip.antiAlias,
border: Border.all(color: data.accent.withValues(alpha: 0.14)), child: SizedBox(
), height: 420,
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
width: 36,
height: 36,
decoration: BoxDecoration(
color: data.accent.withValues(alpha: 0.14),
borderRadius: BorderRadius.circular(12),
),
child: Icon(data.icon, color: data.accent, size: 20),
),
const SizedBox(width: 12),
Expanded(
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Text( Padding(
data.label, padding: const EdgeInsets.fromLTRB(16, 14, 8, 8),
style: Theme.of(context).textTheme.labelMedium?.copyWith( child: Row(
color: data.accent, children: [
fontWeight: FontWeight.w700, Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
data.label,
style: Theme.of(context).textTheme.titleMedium,
),
const SizedBox(height: 4),
Text(
data.value,
style: Theme.of(context).textTheme.bodyMedium,
),
if (data.secondaryValue != null)
Text(
data.secondaryValue!,
style: Theme.of(context).textTheme.bodySmall,
),
],
),
),
IconButton(
onPressed: () => Navigator.of(dialogContext).pop(),
icon: const Icon(Icons.close),
),
],
), ),
), ),
const SizedBox(height: 6), Expanded(
Text( child: flutter_map.FlutterMap(
data.value, options: flutter_map.MapOptions(
style: Theme.of(context).textTheme.titleLarge?.copyWith( initialCenter: location,
fontWeight: FontWeight.w700, initialZoom: 15,
height: 1.1, ),
children: [
flutter_map.TileLayer(
urlTemplate:
'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
userAgentPackageName:
'com.meshcore.sar.meshcore_sar_app',
),
flutter_map.MarkerLayer(
markers: [
flutter_map.Marker(
point: location,
width: 40,
height: 40,
child: Icon(
Icons.location_on,
color: data.accent,
size: 34,
),
),
],
),
],
), ),
), ),
], ],
), ),
), ),
], );
},
);
}
@override
Widget build(BuildContext context) {
return Container(
width: width,
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: data.accent.withValues(alpha: 0.08),
borderRadius: BorderRadius.circular(22),
border: Border.all(color: data.accent.withValues(alpha: 0.14)),
), ),
child: data.mapLocation == null
? Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_MetricIcon(accent: data.accent, icon: data.icon),
const SizedBox(width: 10),
Expanded(child: _MetricText(data: data)),
],
)
: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_MetricIcon(accent: data.accent, icon: data.icon),
const SizedBox(width: 10),
Expanded(child: _MetricText(data: data)),
],
),
const SizedBox(height: 10),
Material(
color: Colors.transparent,
child: InkWell(
borderRadius: BorderRadius.circular(14),
onTap: () => _showExpandedMap(context),
child: ClipRRect(
borderRadius: BorderRadius.circular(14),
child: SizedBox(
height: 104,
width: double.infinity,
child: Stack(
children: [
flutter_map.FlutterMap(
options: flutter_map.MapOptions(
initialCenter: data.mapLocation!,
initialZoom: 14,
interactionOptions:
const flutter_map.InteractionOptions(
flags: flutter_map.InteractiveFlag.none,
),
),
children: [
flutter_map.TileLayer(
urlTemplate:
'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
userAgentPackageName:
'com.meshcore.sar.meshcore_sar_app',
),
flutter_map.MarkerLayer(
markers: [
flutter_map.Marker(
point: data.mapLocation!,
width: 32,
height: 32,
child: Icon(
Icons.location_on,
color: data.accent,
size: 28,
),
),
],
),
],
),
Positioned(
right: 8,
bottom: 8,
child: Container(
padding: const EdgeInsets.symmetric(
horizontal: 6,
vertical: 3,
),
decoration: BoxDecoration(
color: Colors.black.withValues(alpha: 0.55),
borderRadius: BorderRadius.circular(999),
),
child: const Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
Icons.open_in_full,
size: 12,
color: Colors.white,
),
SizedBox(width: 4),
Text(
'Open map',
style: TextStyle(
color: Colors.white,
fontSize: 11,
fontWeight: FontWeight.w600,
),
),
],
),
),
),
],
),
),
),
),
),
],
),
);
}
}
class _MetricIcon extends StatelessWidget {
final Color accent;
final IconData icon;
const _MetricIcon({required this.accent, required this.icon});
@override
Widget build(BuildContext context) {
return Container(
width: 32,
height: 32,
decoration: BoxDecoration(
color: accent.withValues(alpha: 0.14),
borderRadius: BorderRadius.circular(12),
),
child: Icon(icon, color: accent, size: 18),
);
}
}
class _MetricText extends StatelessWidget {
final _MetricCardData data;
const _MetricText({required this.data});
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
data.label,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: Theme.of(context).textTheme.labelMedium?.copyWith(
color: data.accent,
fontWeight: FontWeight.w700,
),
),
const SizedBox(height: 4),
Text(
data.value,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: Theme.of(context).textTheme.titleSmall?.copyWith(
fontWeight: FontWeight.w700,
height: 1.1,
),
),
if (data.secondaryValue != null) ...[
const SizedBox(height: 4),
Text(
data.secondaryValue!,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
fontWeight: FontWeight.w600,
),
),
],
],
); );
} }
} }
class _MetricCardData { class _MetricCardData {
final String fieldKey;
final IconData icon; final IconData icon;
final String label; final String label;
final String value; final String value;
final String? secondaryValue;
final Color accent; final Color accent;
final bool wide; final bool wide;
final LatLng? mapLocation;
const _MetricCardData({ const _MetricCardData({
required this.fieldKey,
required this.icon, required this.icon,
required this.label, required this.label,
required this.value, required this.value,
this.secondaryValue,
required this.accent, required this.accent,
this.wide = false, this.wide = false,
this.mapLocation,
}); });
} }
String _metricLabel(SensorMetric metric) { class _FieldOption {
return switch (metric) { final String key;
SensorMetric.lastSeen => 'Last seen', final String label;
SensorMetric.voltage => 'Voltage',
SensorMetric.battery => 'Battery', const _FieldOption({required this.key, required this.label});
SensorMetric.temperature => 'Temperature', }
SensorMetric.humidity => 'Humidity',
SensorMetric.pressure => 'Pressure', List<_FieldOption> _fieldOptionsFor(Contact? contact) {
SensorMetric.gps => 'GPS', final telemetry = contact?.telemetry;
SensorMetric.updated => 'Updated', final options = <_FieldOption>[
if (telemetry?.batteryMilliVolts != null)
const _FieldOption(key: 'voltage', label: 'Voltage'),
if (telemetry?.batteryPercentage != null)
const _FieldOption(key: 'battery', label: 'Battery'),
if (telemetry?.temperature != null)
const _FieldOption(key: 'temperature', label: 'Temperature'),
if (telemetry?.humidity != null)
const _FieldOption(key: 'humidity', label: 'Humidity'),
if (telemetry?.pressure != null)
const _FieldOption(key: 'pressure', label: 'Pressure'),
if (telemetry?.gpsLocation != null)
const _FieldOption(key: 'gps', label: 'GPS'),
];
final extraSensorData = telemetry?.extraSensorData;
if (extraSensorData != null) {
for (final key in extraSensorData.keys) {
options.add(
_FieldOption(
key: _extraFieldKey(key),
label: _formatExtraFieldLabel(key),
),
);
}
}
return options;
}
String _extraFieldKey(String label) {
return 'extra:$label';
}
String _formatExtraFieldLabel(String rawKey) {
final knownPrefixes = <String, String>{
'altitude': 'Altitude',
'illuminance': 'Illuminance',
'presence': 'Presence',
'digital_input': 'Digital input',
'digital_output': 'Digital output',
'analog_input': 'Analog input',
'analog_output': 'Analog output',
'accelerometer': 'Accelerometer',
'gyrometer': 'Gyrometer',
}; };
for (final entry in knownPrefixes.entries) {
final prefix = '${entry.key}_';
if (rawKey == entry.key) {
return entry.value;
}
if (rawKey.startsWith(prefix)) {
final suffix = rawKey.substring(prefix.length);
final channel = int.tryParse(suffix);
if (channel != null) {
return '${entry.value} (ch $channel)';
}
return entry.value;
}
}
final parts = rawKey.split('_');
if (parts.isEmpty) return rawKey;
final channel = parts.length > 1 ? parts.last : null;
final base = parts.length > 1
? parts.sublist(0, parts.length - 1).join(' ')
: rawKey;
final title = base
.split(' ')
.where((part) => part.isNotEmpty)
.map((part) => '${part[0].toUpperCase()}${part.substring(1)}')
.join(' ');
if (channel != null && int.tryParse(channel) != null) {
return '$title (ch $channel)';
}
return title;
} }
IconData _typeIcon(Contact contact) { IconData _typeIcon(Contact contact) {

View File

@@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts # In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix. # of the product and file versions while build-number is used as the build suffix.
version: 2026.0307.4+17 version: 2026.0307.6+19
environment: environment:
sdk: ^3.9.2 sdk: ^3.9.2