mirror of
https://github.com/wger-project/flutter.git
synced 2026-12-03 02:24:30 +01:00
Remove unused symbols
This commit is contained in:
@@ -60,8 +60,6 @@ class HealthMetric {
|
||||
required this.toCategoryValue,
|
||||
this.dailyAggregation,
|
||||
this.dayRollsOverAtHour,
|
||||
this.enabled = false,
|
||||
this.disabledReason,
|
||||
this.readWindow = defaultReadWindow,
|
||||
}) : components = const [];
|
||||
|
||||
@@ -74,8 +72,6 @@ class HealthMetric {
|
||||
required this.toCategoryValue,
|
||||
this.dailyAggregation,
|
||||
this.dayRollsOverAtHour,
|
||||
this.enabled = false,
|
||||
this.disabledReason,
|
||||
this.readWindow = defaultReadWindow,
|
||||
}) : dataType = null;
|
||||
|
||||
@@ -113,13 +109,6 @@ class HealthMetric {
|
||||
/// 23:30 belongs to the following day. `null` buckets by plain calendar day.
|
||||
final int? dayRollsOverAtHour;
|
||||
|
||||
/// Whether V1 imports this metric. Disabled ones are declared for visibility
|
||||
/// and blocked on further groundwork (see [disabledReason]).
|
||||
final bool enabled;
|
||||
|
||||
/// Why a declared metric is not imported yet.
|
||||
final String? disabledReason;
|
||||
|
||||
/// How much of the timeline one platform query may cover for this metric.
|
||||
///
|
||||
/// The plugin materialises every record it reads and then serialises the
|
||||
@@ -168,17 +157,13 @@ double _identity(double raw) => raw;
|
||||
/// Both platforms report a distance in meters, the category stores kilometers.
|
||||
double _metersToKm(double raw) => raw / 1000;
|
||||
|
||||
/// The V1 metric set (see `plan-measurements-health-v27.md`).
|
||||
///
|
||||
/// Only [HealthMetric.enabled] entries are imported. A disabled one stays
|
||||
/// declared so the mapping is visible in one place, with the groundwork it
|
||||
/// waits for in its [HealthMetric.disabledReason].
|
||||
/// The V1 metric set (see `plan-measurements-health-v27.md`), all of which
|
||||
/// the importer pulls.
|
||||
const List<HealthMetric> healthMetrics = [
|
||||
HealthMetric(
|
||||
metricType: MetricType.bodyFat,
|
||||
dataType: HealthDataType.BODY_FAT_PERCENTAGE,
|
||||
toCategoryValue: _bodyFatToPercent,
|
||||
enabled: true,
|
||||
),
|
||||
HealthMetric(
|
||||
// Both platforms report kilograms, like body weight. Unlike it, the
|
||||
@@ -187,19 +172,16 @@ const List<HealthMetric> healthMetrics = [
|
||||
metricType: MetricType.leanBodyMass,
|
||||
dataType: HealthDataType.LEAN_BODY_MASS,
|
||||
toCategoryValue: _identity,
|
||||
enabled: true,
|
||||
),
|
||||
HealthMetric(
|
||||
metricType: MetricType.height,
|
||||
dataType: HealthDataType.HEIGHT,
|
||||
toCategoryValue: _heightToCm,
|
||||
enabled: true,
|
||||
),
|
||||
HealthMetric(
|
||||
metricType: MetricType.bodyWeight,
|
||||
dataType: HealthDataType.WEIGHT,
|
||||
toCategoryValue: _identity,
|
||||
enabled: true,
|
||||
),
|
||||
HealthMetric.group(
|
||||
metricType: MetricType.bloodPressure,
|
||||
@@ -214,14 +196,12 @@ const List<HealthMetric> healthMetrics = [
|
||||
dataTypes: [HealthDataType.BLOOD_PRESSURE_DIASTOLIC],
|
||||
),
|
||||
],
|
||||
enabled: true,
|
||||
),
|
||||
HealthMetric(
|
||||
metricType: MetricType.heartRate,
|
||||
dataType: HealthDataType.HEART_RATE,
|
||||
toCategoryValue: _identity,
|
||||
dailyAggregation: DailyAggregation.average,
|
||||
enabled: true,
|
||||
readWindow: highVolumeReadWindow,
|
||||
),
|
||||
HealthMetric(
|
||||
@@ -231,7 +211,6 @@ const List<HealthMetric> healthMetrics = [
|
||||
metricType: MetricType.restingHeartRate,
|
||||
dataType: HealthDataType.RESTING_HEART_RATE,
|
||||
toCategoryValue: _identity,
|
||||
enabled: true,
|
||||
),
|
||||
HealthMetric(
|
||||
// A single saturation says little on its own, and a wearable measures it
|
||||
@@ -241,7 +220,6 @@ const List<HealthMetric> healthMetrics = [
|
||||
dataType: HealthDataType.BLOOD_OXYGEN,
|
||||
toCategoryValue: _saturationToPercent,
|
||||
dailyAggregation: DailyAggregation.average,
|
||||
enabled: true,
|
||||
readWindow: highVolumeReadWindow,
|
||||
),
|
||||
HealthMetric.group(
|
||||
@@ -274,7 +252,6 @@ const List<HealthMetric> healthMetrics = [
|
||||
],
|
||||
dailyAggregation: DailyAggregation.mergedDuration,
|
||||
dayRollsOverAtHour: 18,
|
||||
enabled: true,
|
||||
),
|
||||
// The three cumulative types below are counters, not measurements: a single
|
||||
// record covers a few minutes and means nothing on its own, so only the
|
||||
@@ -286,7 +263,6 @@ const List<HealthMetric> healthMetrics = [
|
||||
dataType: HealthDataType.STEPS,
|
||||
toCategoryValue: _identity,
|
||||
dailyAggregation: DailyAggregation.sum,
|
||||
enabled: true,
|
||||
readWindow: highVolumeReadWindow,
|
||||
),
|
||||
HealthMetric(
|
||||
@@ -294,7 +270,6 @@ const List<HealthMetric> healthMetrics = [
|
||||
dataType: HealthDataType.DISTANCE_DELTA,
|
||||
toCategoryValue: _metersToKm,
|
||||
dailyAggregation: DailyAggregation.sum,
|
||||
enabled: true,
|
||||
readWindow: highVolumeReadWindow,
|
||||
),
|
||||
HealthMetric(
|
||||
@@ -305,15 +280,10 @@ const List<HealthMetric> healthMetrics = [
|
||||
dataType: HealthDataType.ACTIVE_ENERGY_BURNED,
|
||||
toCategoryValue: _identity,
|
||||
dailyAggregation: DailyAggregation.sum,
|
||||
enabled: true,
|
||||
readWindow: highVolumeReadWindow,
|
||||
),
|
||||
];
|
||||
|
||||
/// The enabled subset that the importer actually pulls.
|
||||
List<HealthMetric> get enabledHealthMetrics => healthMetrics.where((m) => m.enabled).toList();
|
||||
|
||||
/// Every platform data type the enabled metrics are made of, i.e. what
|
||||
/// permissions are asked for and what is checked as readable.
|
||||
List<HealthDataType> get enabledHealthDataTypes =>
|
||||
enabledHealthMetrics.expand((m) => m.dataTypes).toList();
|
||||
/// Every platform data type the metrics are made of, i.e. what permissions
|
||||
/// are asked for and what is checked as readable.
|
||||
List<HealthDataType> get healthDataTypes => healthMetrics.expand((m) => m.dataTypes).toList();
|
||||
|
||||
@@ -132,19 +132,17 @@ class HealthImporter {
|
||||
_outOfRangeCount = 0;
|
||||
|
||||
try {
|
||||
final readable = await _health.readableTypes(enabledHealthDataTypes);
|
||||
final metrics = enabledHealthMetrics
|
||||
.where((m) => m.dataTypes.every(readable.contains))
|
||||
.toList();
|
||||
final readable = await _health.readableTypes(healthDataTypes);
|
||||
final metrics = healthMetrics.where((m) => m.dataTypes.every(readable.contains)).toList();
|
||||
if (metrics.isEmpty) {
|
||||
_logger.warning('Health permissions not granted, skipping sync');
|
||||
return (imported: 0, issue: HealthSyncIssue.permissionsMissing, completed: false);
|
||||
}
|
||||
if (metrics.length < enabledHealthMetrics.length) {
|
||||
if (metrics.length < healthMetrics.length) {
|
||||
// A declined type costs its own metric its import, nothing else. Both
|
||||
// platforms hand out access per type, so this is the normal state
|
||||
// after a user unticked one, not an error
|
||||
final blocked = enabledHealthMetrics.where((m) => !metrics.contains(m));
|
||||
final blocked = healthMetrics.where((m) => !metrics.contains(m));
|
||||
_logger.info(
|
||||
'No access to ${blocked.map((m) => m.metricType.name).join(', ')}, '
|
||||
'importing the remaining ${metrics.length} metrics',
|
||||
|
||||
@@ -56,9 +56,6 @@ class HealthRepository {
|
||||
/// for Apple Health, `google` for Health Connect.
|
||||
String get sourceName => Platform.isIOS ? 'apple' : 'google';
|
||||
|
||||
/// Whether a health platform is usable on this device.
|
||||
Future<bool> isAvailable() async => await availability() == HealthPlatformAvailability.available;
|
||||
|
||||
/// How usable the device's health platform is.
|
||||
///
|
||||
/// Android tells the two unusable cases apart, and both are the user's to
|
||||
|
||||
@@ -91,9 +91,6 @@ class HealthSyncNotifier extends _$HealthSyncNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether a health platform is available on this device.
|
||||
Future<bool> isAvailable() => _health.isAvailable();
|
||||
|
||||
/// How usable the device's health platform is, so the settings can offer
|
||||
/// installing or updating Health Connect instead of hiding the feature.
|
||||
Future<HealthPlatformAvailability> availability() => _health.availability();
|
||||
@@ -107,7 +104,7 @@ class HealthSyncNotifier extends _$HealthSyncNotifier {
|
||||
/// permissions were not granted (sync stays disabled).
|
||||
Future<int?> enableSync() async {
|
||||
_logger.info('Enabling health sync');
|
||||
if (!await _health.ensureAuthorized(enabledHealthDataTypes)) {
|
||||
if (!await _health.ensureAuthorized(healthDataTypes)) {
|
||||
return null;
|
||||
}
|
||||
await PreferenceHelper.instance.setHealthSyncEnabled(true);
|
||||
@@ -123,7 +120,7 @@ class HealthSyncNotifier extends _$HealthSyncNotifier {
|
||||
/// not granted.
|
||||
Future<int?> retryWithPermissions() async {
|
||||
_logger.info('Re-requesting health permissions');
|
||||
if (!await _health.ensureAuthorized(enabledHealthDataTypes)) {
|
||||
if (!await _health.ensureAuthorized(healthDataTypes)) {
|
||||
state = state.copyWith(issue: HealthSyncIssue.permissionsMissing);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -178,30 +178,6 @@ List<MeasurementChartEntry> weeklyDeltas(
|
||||
];
|
||||
}
|
||||
|
||||
/// Turns stored entries into chart points, converting the value to [targetUnit].
|
||||
///
|
||||
/// Entries stored as a daily aggregate keep the range they summarise in
|
||||
/// `extra_data` (heart rate min/max); it is lifted onto the point so the chart
|
||||
/// draws a band around the line. Those bounds share the value's unit and are
|
||||
/// converted along with it.
|
||||
List<MeasurementChartEntry> chartEntriesFor(
|
||||
List<MeasurementEntry> entries, {
|
||||
required String targetUnit,
|
||||
required String categoryUnit,
|
||||
}) => entries.map((entry) {
|
||||
num? bound(String key) {
|
||||
final stored = entry.extraData?[key];
|
||||
return stored is num ? entry.boundIn(stored, targetUnit, categoryUnit: categoryUnit) : null;
|
||||
}
|
||||
|
||||
return MeasurementChartEntry(
|
||||
entry.valueIn(targetUnit, categoryUnit: categoryUnit),
|
||||
entry.date,
|
||||
min: bound('min'),
|
||||
max: bound('max'),
|
||||
);
|
||||
}).toList();
|
||||
|
||||
/// The point level a category's chart needs.
|
||||
///
|
||||
/// Two charts are built on a calendar unit and fix it: a heatmap draws days, a
|
||||
@@ -240,7 +216,7 @@ MeasurementBucketLevel chartBucketLevel(MetricType metricType, ChartType chartTy
|
||||
|
||||
/// Turns SQL-condensed buckets into chart points, converting to [targetUnit].
|
||||
///
|
||||
/// The counterpart of [chartEntriesFor] for the aggregated read path. A bucket
|
||||
/// Chart points from the aggregated read path. A bucket
|
||||
/// arrives once per unit its entries were written in, so the slices are
|
||||
/// converted before they are merged. Their spread becomes the point's range,
|
||||
/// left off where it says nothing (a single reading, a [summed] total).
|
||||
@@ -482,14 +458,14 @@ ChartType resolveChartTypeForData(
|
||||
? aggregatePerDay(raw).length
|
||||
: raw.map((e) => e.count).sum;
|
||||
|
||||
return readings < distributionMinValues ? metricType.defaultChartType : resolved;
|
||||
return readings < _distributionMinValues ? metricType.defaultChartType : resolved;
|
||||
}
|
||||
|
||||
/// Fewest values a distribution says anything about: below this a histogram
|
||||
/// is noise with gaps, and the chart falls back to the derived default. Same
|
||||
/// principle as a group whose readings are all unpaired falling back to
|
||||
/// lines: never an empty or misleading card.
|
||||
const distributionMinValues = 15;
|
||||
const _distributionMinValues = 15;
|
||||
|
||||
/// Widest a histogram gets, in bins. A single outlier (a lb reading stored
|
||||
/// into a kg category) would otherwise stretch a fixed-width histogram into
|
||||
|
||||
@@ -45,11 +45,11 @@ const sparkMaxWeeks = 52;
|
||||
|
||||
/// Widest window drawn as one slot per day. Beyond it the daily bars fall
|
||||
/// below legibility and the bar family switches to weekly slots.
|
||||
const sparkWeeklyThresholdDays = 35;
|
||||
const _weeklyThresholdDays = 35;
|
||||
|
||||
/// Fewest points in the window before a line spark draws dots instead: a line
|
||||
/// through a handful of readings claims a continuity they do not have.
|
||||
const sparkSparseMinDays = 3;
|
||||
const _sparseMinDays = 3;
|
||||
|
||||
/// The spark a category of [metricType] is drawn as, honoring [picked]
|
||||
/// wherever the format survives miniaturisation.
|
||||
@@ -89,7 +89,7 @@ class SparkWindow {
|
||||
/// passed in (null for the full history).
|
||||
///
|
||||
/// The line follows the filter as it is. The bar family switches to weekly
|
||||
/// slots beyond [sparkWeeklyThresholdDays] and is capped at [sparkMaxWeeks];
|
||||
/// slots beyond [_weeklyThresholdDays] and is capped at [sparkMaxWeeks];
|
||||
/// the heatmap follows it within its own, tighter legibility bounds. The
|
||||
/// delta window gets one slot beyond its weeks for the running week.
|
||||
SparkWindow sparkWindowFor(SparkKind kind, {required DateTime? cutoff, DateTime? today}) {
|
||||
@@ -115,7 +115,7 @@ SparkWindow sparkWindowFor(SparkKind kind, {required DateTime? cutoff, DateTime?
|
||||
);
|
||||
|
||||
case SparkKind.bars:
|
||||
if (days != null && days <= sparkWeeklyThresholdDays) {
|
||||
if (days != null && days <= _weeklyThresholdDays) {
|
||||
return SparkWindow(start: dayOf(cutoff!), days: days);
|
||||
}
|
||||
final weeks = weeksOf(days);
|
||||
@@ -130,8 +130,8 @@ SparkWindow sparkWindowFor(SparkKind kind, {required DateTime? cutoff, DateTime?
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether the window holds too few points for a line, see [sparkSparseMinDays].
|
||||
bool sparkIsSparse(List<MeasurementChartEntry> days) => days.length < sparkSparseMinDays;
|
||||
/// Whether the window holds too few points for a line, see [_sparseMinDays].
|
||||
bool sparkIsSparse(List<MeasurementChartEntry> days) => days.length < _sparseMinDays;
|
||||
|
||||
/// One point per calendar week: the mean of the week's daily values, carrying
|
||||
/// the span of everything measured in it as its range.
|
||||
|
||||
@@ -73,7 +73,7 @@ extension MeasurementChartEntryListExtensions on List<MeasurementChartEntry> {
|
||||
} else {
|
||||
// insert interpolated start value if needed
|
||||
if (!hasEntryOnStartDay && lastBeforeStart != null) {
|
||||
result.insert(0, interpolateBetween(lastBeforeStart, entry, start));
|
||||
result.insert(0, _interpolateBetween(lastBeforeStart, entry, start));
|
||||
hasEntryOnStartDay = true;
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ extension MeasurementChartEntryListExtensions on List<MeasurementChartEntry> {
|
||||
// note: we only interpolate end if we have data going beyond end
|
||||
// if let's say your plan ends in a week from now, we wouldn't want to fake data until next week.
|
||||
if (!hasEntryOnEndDay && lastBeforeEnd != null) {
|
||||
result.add(interpolateBetween(lastBeforeEnd, entry, end!));
|
||||
result.add(_interpolateBetween(lastBeforeEnd, entry, end!));
|
||||
hasEntryOnEndDay = true;
|
||||
}
|
||||
// we added all our values and did all interpolations
|
||||
@@ -98,7 +98,7 @@ extension MeasurementChartEntryListExtensions on List<MeasurementChartEntry> {
|
||||
}
|
||||
|
||||
// caller needs to make sure that before.date < date < after.date
|
||||
MeasurementChartEntry interpolateBetween(
|
||||
MeasurementChartEntry _interpolateBetween(
|
||||
MeasurementChartEntry before,
|
||||
MeasurementChartEntry after,
|
||||
DateTime date,
|
||||
|
||||
@@ -48,7 +48,7 @@ sealed class CalculationParam {
|
||||
/// no end, and a category whose unit is not among these is offered but
|
||||
/// disabled, which shows the user what to change instead of hiding the
|
||||
/// category from them.
|
||||
const lengthUnits = [
|
||||
const _lengthUnits = [
|
||||
'mm',
|
||||
'millimeter',
|
||||
'millimeters',
|
||||
@@ -138,7 +138,7 @@ const calculationTypes = <CalculationType>[
|
||||
// A ratio of two lengths, so the number carries no unit
|
||||
unit: '',
|
||||
params: [
|
||||
CategoryParam('category_id', unitFilter: lengthUnits),
|
||||
CategoryParam('category_id', unitFilter: _lengthUnits),
|
||||
],
|
||||
needsHeight: true,
|
||||
),
|
||||
|
||||
@@ -30,7 +30,7 @@ part 'measurement_category.freezed.dart';
|
||||
/// MUST stay identical to CATEGORY_NAMESPACE on the server: a UUIDv5 hashes
|
||||
/// namespace and name together, so a different constant here derives different
|
||||
/// ids and the whole point of [deterministicCategoryId] collapses.
|
||||
const categoryIdNamespace = '4c5ef6dd-97c9-5b18-9f8b-2a5c1ed70a2f';
|
||||
const _categoryIdNamespace = '4c5ef6dd-97c9-5b18-9f8b-2a5c1ed70a2f';
|
||||
|
||||
/// The id the category of [metricType] has for the user [userId].
|
||||
///
|
||||
@@ -40,7 +40,7 @@ const categoryIdNamespace = '4c5ef6dd-97c9-5b18-9f8b-2a5c1ed70a2f';
|
||||
/// acknowledges the second push as a no-op instead of rejecting it against its
|
||||
/// uniqueness constraint.
|
||||
String deterministicCategoryId(String userId, MetricType metricType) =>
|
||||
ps.uuid.v5(categoryIdNamespace, '$userId:${metricType.wireValue}');
|
||||
ps.uuid.v5(_categoryIdNamespace, '$userId:${metricType.wireValue}');
|
||||
|
||||
/// Largest value the server's column can hold (numeric(8, 2)). It is what a
|
||||
/// category without a metric type is bounded by, since nothing about a
|
||||
|
||||
@@ -33,7 +33,7 @@ import 'package:wger/features/measurements/widgets/forms/entry.dart';
|
||||
import 'package:wger/features/measurements/widgets/forms/group_entry.dart';
|
||||
import 'package:wger/l10n/generated/app_localizations.dart';
|
||||
|
||||
enum MeasurementOptions {
|
||||
enum _MeasurementOptions {
|
||||
edit,
|
||||
delete,
|
||||
}
|
||||
@@ -81,11 +81,11 @@ class _MeasurementEntriesScreenState extends ConsumerState<MeasurementEntriesScr
|
||||
title: Text(category?.displayName(context) ?? ''),
|
||||
actions: [
|
||||
if (category != null)
|
||||
PopupMenuButton<MeasurementOptions>(
|
||||
PopupMenuButton<_MeasurementOptions>(
|
||||
icon: const Icon(Icons.more_vert),
|
||||
onSelected: (value) {
|
||||
switch (value) {
|
||||
case MeasurementOptions.edit:
|
||||
case _MeasurementOptions.edit:
|
||||
Navigator.pushNamed(
|
||||
context,
|
||||
FormScreen.routeName,
|
||||
@@ -97,7 +97,7 @@ class _MeasurementEntriesScreenState extends ConsumerState<MeasurementEntriesScr
|
||||
);
|
||||
break;
|
||||
|
||||
case MeasurementOptions.delete:
|
||||
case _MeasurementOptions.delete:
|
||||
showConfirmDeleteDialog(
|
||||
context,
|
||||
itemName: category.displayName(context),
|
||||
@@ -112,12 +112,12 @@ class _MeasurementEntriesScreenState extends ConsumerState<MeasurementEntriesScr
|
||||
itemBuilder: (context) {
|
||||
return [
|
||||
if (category.isEditable)
|
||||
PopupMenuItem<MeasurementOptions>(
|
||||
value: MeasurementOptions.edit,
|
||||
PopupMenuItem<_MeasurementOptions>(
|
||||
value: _MeasurementOptions.edit,
|
||||
child: Text(AppLocalizations.of(context).edit),
|
||||
),
|
||||
PopupMenuItem<MeasurementOptions>(
|
||||
value: MeasurementOptions.delete,
|
||||
PopupMenuItem<_MeasurementOptions>(
|
||||
value: _MeasurementOptions.delete,
|
||||
child: Text(AppLocalizations.of(context).delete),
|
||||
),
|
||||
];
|
||||
|
||||
@@ -28,10 +28,10 @@ import 'package:intl/intl.dart';
|
||||
import 'package:wger/core/formatting/formatting.dart';
|
||||
|
||||
/// Number of dates to label on the x axis
|
||||
const X_LABEL_COUNT = 4;
|
||||
const _xLabelCount = 4;
|
||||
|
||||
/// Widest a single bar gets, for charts with only a handful of entries
|
||||
const MAX_BAR_WIDTH = 12.0;
|
||||
const _maxBarWidth = 12.0;
|
||||
|
||||
const hiddenTitles = AxisTitles(sideTitles: SideTitles(showTitles: false));
|
||||
|
||||
@@ -73,8 +73,8 @@ AxisTitles valueTitles(BuildContext context, String unit, double? interval) => A
|
||||
/// The date axis of the bar charts, which draw one title per group: their x
|
||||
/// value is a position in [dates] rather than a timestamp, so thinning the
|
||||
/// labels out has to happen here.
|
||||
AxisTitles dateIndexTitles(BuildContext context, List<DateTime> dates) {
|
||||
final labelStep = max(1, (dates.length / X_LABEL_COUNT).ceil());
|
||||
AxisTitles _dateIndexTitles(BuildContext context, List<DateTime> dates) {
|
||||
final labelStep = max(1, (dates.length / _xLabelCount).ceil());
|
||||
// keep the labels away from the chart edges
|
||||
final labelOffset = labelStep ~/ 2;
|
||||
final spansYears = dates.isNotEmpty && dates.first.year != dates.last.year;
|
||||
@@ -112,7 +112,7 @@ FlTitlesData barTitlesData(
|
||||
show: true,
|
||||
rightTitles: hiddenTitles,
|
||||
topTitles: hiddenTitles,
|
||||
bottomTitles: dateIndexTitles(context, dates),
|
||||
bottomTitles: _dateIndexTitles(context, dates),
|
||||
leftTitles: valueTitles(context, unit, interval),
|
||||
);
|
||||
|
||||
@@ -120,7 +120,7 @@ FlTitlesData barTitlesData(
|
||||
/// between them, but never go below a hairline. Without it a couple of months
|
||||
/// of readings overlap into a solid block.
|
||||
double barWidth(int count, double availableWidth) =>
|
||||
count == 0 ? MAX_BAR_WIDTH : (availableWidth / count * 0.7).clamp(1.0, MAX_BAR_WIDTH);
|
||||
count == 0 ? _maxBarWidth : (availableWidth / count * 0.7).clamp(1.0, _maxBarWidth);
|
||||
|
||||
/// Horizontal lines only: a vertical one per bar would only repeat the bars.
|
||||
FlGridData barGrid(BuildContext context) => FlGridData(
|
||||
|
||||
@@ -43,9 +43,6 @@ class _FakeHealthSyncNotifier extends HealthSyncNotifier {
|
||||
@override
|
||||
HealthSyncState build() => initialState;
|
||||
|
||||
@override
|
||||
Future<bool> isAvailable() async => platformAvailability == HealthPlatformAvailability.available;
|
||||
|
||||
@override
|
||||
Future<HealthPlatformAvailability> availability() async => platformAvailability;
|
||||
|
||||
|
||||
@@ -38,9 +38,6 @@ class _FakeHealthSyncNotifier extends HealthSyncNotifier {
|
||||
@override
|
||||
HealthSyncState build() => const HealthSyncState();
|
||||
|
||||
@override
|
||||
Future<bool> isAvailable() async => false;
|
||||
|
||||
@override
|
||||
Future<HealthPlatformAvailability> availability() async => HealthPlatformAvailability.unsupported;
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ void main() {
|
||||
// Health Connect can only grant what the manifest declares, and it
|
||||
// reports an undeclared type as not granted rather than as an error, so
|
||||
// a forgotten entry costs that metric its import without a trace
|
||||
for (final metric in enabledHealthMetrics) {
|
||||
for (final metric in healthMetrics) {
|
||||
for (final type in metric.dataTypes) {
|
||||
final permission = _readPermissions[type];
|
||||
expect(
|
||||
|
||||
@@ -27,7 +27,7 @@ void main() {
|
||||
group('Enabled metric set', () {
|
||||
test('every declared metric is imported', () {
|
||||
expect(
|
||||
enabledHealthMetrics.map((m) => m.metricType),
|
||||
healthMetrics.map((m) => m.metricType),
|
||||
containsAll([
|
||||
MetricType.bodyFat,
|
||||
MetricType.leanBodyMass,
|
||||
@@ -43,7 +43,7 @@ void main() {
|
||||
MetricType.energy,
|
||||
]),
|
||||
);
|
||||
expect(enabledHealthMetrics.length, 12);
|
||||
expect(healthMetrics.length, 12);
|
||||
});
|
||||
|
||||
test('daily aggregation is set per metric', () {
|
||||
@@ -93,12 +93,6 @@ void main() {
|
||||
}
|
||||
});
|
||||
|
||||
test('every disabled metric explains why', () {
|
||||
// Nothing is parked at the moment; the rule is for the next type that is
|
||||
// declared before its groundwork exists
|
||||
expect(healthMetrics.where((m) => !m.enabled).every((m) => m.disabledReason != null), isTrue);
|
||||
});
|
||||
|
||||
test('metric types are unique', () {
|
||||
final types = healthMetrics.map((m) => m.metricType).toList();
|
||||
expect(types.length, types.toSet().length);
|
||||
@@ -140,11 +134,4 @@ void main() {
|
||||
expect(height.toCategoryValue(180), closeTo(180, 0.001));
|
||||
});
|
||||
});
|
||||
|
||||
test('enabledHealthMetrics matches the enabled flag', () {
|
||||
expect(
|
||||
enabledHealthMetrics,
|
||||
healthMetrics.where((m) => m.enabled).toList(),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ void main() {
|
||||
/// imported before looks like.
|
||||
Future<void> seedWatermarks(String timestamp) =>
|
||||
PreferenceHelper.instance.setHealthSyncWatermarks({
|
||||
for (final metric in enabledHealthMetrics) metric.metricType.name: timestamp,
|
||||
for (final metric in healthMetrics) metric.metricType.name: timestamp,
|
||||
});
|
||||
|
||||
/// How far [type] has been imported, null while it has no watermark.
|
||||
@@ -133,7 +133,7 @@ void main() {
|
||||
/// starting from the watermark.
|
||||
List<MeasurementCategory> categoriesForEveryMetric() {
|
||||
final categories = <MeasurementCategory>[];
|
||||
for (final metric in enabledHealthMetrics) {
|
||||
for (final metric in healthMetrics) {
|
||||
if (metric.metricType == MetricType.bodyWeight) {
|
||||
categories.add(
|
||||
MeasurementCategory(
|
||||
@@ -291,7 +291,7 @@ void main() {
|
||||
// Both platforms hand out access per type, and Health Connect invites
|
||||
// the user to untick single ones, so one declined type must not stop
|
||||
// everything else
|
||||
final bloodPressure = enabledHealthMetrics.firstWhere(
|
||||
final bloodPressure = healthMetrics.firstWhere(
|
||||
(m) => m.metricType == MetricType.bloodPressure,
|
||||
);
|
||||
when(health.readableTypes(any)).thenAnswer(
|
||||
@@ -338,7 +338,7 @@ void main() {
|
||||
// is years of platform records read to import nothing
|
||||
await seedWatermarks('2026-06-01T12:00:00.000');
|
||||
await PreferenceHelper.instance.setHealthSyncReadableTypes([
|
||||
for (final metric in enabledHealthMetrics)
|
||||
for (final metric in healthMetrics)
|
||||
for (final type in metric.dataTypes)
|
||||
if (type != HealthDataType.BODY_FAT_PERCENTAGE) type.name,
|
||||
]);
|
||||
@@ -356,7 +356,7 @@ void main() {
|
||||
test('stays on the watermark while the readable types are unchanged', () async {
|
||||
await seedWatermarks('2026-06-01T12:00:00.000');
|
||||
await PreferenceHelper.instance.setHealthSyncReadableTypes([
|
||||
for (final metric in enabledHealthMetrics)
|
||||
for (final metric in healthMetrics)
|
||||
for (final type in metric.dataTypes) type.name,
|
||||
]);
|
||||
when(measurements.getCategoriesOnce()).thenAnswer((_) async => categoriesForEveryMetric());
|
||||
|
||||
@@ -24,7 +24,6 @@ import 'package:wger/features/measurements/charts/range.dart';
|
||||
import 'package:wger/features/measurements/charts/series.dart';
|
||||
import 'package:wger/features/measurements/models/measurement_bucket.dart';
|
||||
import 'package:wger/features/measurements/models/measurement_category.dart';
|
||||
import 'package:wger/features/measurements/models/measurement_entry.dart';
|
||||
|
||||
void main() {
|
||||
MeasurementChartEntry entry(num value, DateTime date) => MeasurementChartEntry(value, date);
|
||||
@@ -331,46 +330,6 @@ void main() {
|
||||
});
|
||||
});
|
||||
|
||||
group('chartEntriesFor', () {
|
||||
test('converts the aggregate bounds along with the value', () {
|
||||
// Reading the value in lb but the bounds in kg would put the band a
|
||||
// factor 2.2 off the line it is supposed to wrap
|
||||
final points = chartEntriesFor(
|
||||
[
|
||||
MeasurementEntry(
|
||||
categoryId: 'c',
|
||||
date: DateTime(2026, 1, 1),
|
||||
value: 80,
|
||||
notes: '',
|
||||
extraData: const {'min': 70, 'max': 90},
|
||||
),
|
||||
],
|
||||
targetUnit: 'lb',
|
||||
categoryUnit: 'kg',
|
||||
);
|
||||
|
||||
expect(points.single.value, 176.37);
|
||||
expect(points.single.min, 154.32);
|
||||
expect(points.single.max, 198.42);
|
||||
});
|
||||
|
||||
test('leaves entries without bounds unranged', () {
|
||||
final points = chartEntriesFor(
|
||||
[
|
||||
MeasurementEntry(
|
||||
categoryId: 'c',
|
||||
date: DateTime(2026, 1, 1),
|
||||
value: 80,
|
||||
notes: '',
|
||||
),
|
||||
],
|
||||
targetUnit: 'kg',
|
||||
categoryUnit: 'kg',
|
||||
);
|
||||
|
||||
expect(points.single.hasRange, isFalse);
|
||||
});
|
||||
});
|
||||
group('chartEntriesForBuckets', () {
|
||||
MeasurementBucket bucket(
|
||||
num sum, {
|
||||
|
||||
Reference in New Issue
Block a user