mirror of
https://github.com/wger-project/flutter.git
synced 2026-12-04 12:42:22 +01:00
Merge branch 'feature/health-sync' into feat/healthsync--sort-measurements-categories-1258
This commit is contained in:
@@ -1,2 +1 @@
|
||||
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
|
||||
#include "Generated.xcconfig"
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
|
||||
#include "Generated.xcconfig"
|
||||
|
||||
@@ -77,7 +77,6 @@
|
||||
9740EEB11CF90186004384FC /* Flutter */,
|
||||
97C146F01CF9000F007C117D /* Runner */,
|
||||
97C146EF1CF9000F007C117D /* Products */,
|
||||
BB0286322FD60C00014F981C /* Pods */,
|
||||
);
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
@@ -105,13 +104,6 @@
|
||||
path = Runner;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
BB0286322FD60C00014F981C /* Pods */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
);
|
||||
path = Pods;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXGroup section */
|
||||
|
||||
/* Begin PBXNativeTarget section */
|
||||
@@ -295,7 +287,7 @@
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
|
||||
MTL_ENABLE_DEBUG_INFO = NO;
|
||||
SDKROOT = iphoneos;
|
||||
SUPPORTED_PLATFORMS = iphoneos;
|
||||
@@ -383,7 +375,7 @@
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
|
||||
MTL_ENABLE_DEBUG_INFO = YES;
|
||||
ONLY_ACTIVE_ARCH = YES;
|
||||
SDKROOT = iphoneos;
|
||||
@@ -432,7 +424,7 @@
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
|
||||
MTL_ENABLE_DEBUG_INFO = NO;
|
||||
SDKROOT = iphoneos;
|
||||
SUPPORTED_PLATFORMS = iphoneos;
|
||||
|
||||
@@ -45,7 +45,10 @@ class _DashboardMeasurementWidgetState extends ConsumerState<DashboardMeasuremen
|
||||
return AsyncValueWidget<List<MeasurementCategory>>(
|
||||
value: ref.watch(measurementProvider),
|
||||
loggerName: 'DashboardMeasurementWidget',
|
||||
data: (categoriesList) {
|
||||
data: (allCategories) {
|
||||
// Children of multi-value groups are shown inside their parent's card
|
||||
final categoriesList = allCategories.where((c) => c.parentId == null).toList();
|
||||
|
||||
if (categoriesList.isEmpty) {
|
||||
return NothingFound(
|
||||
AppLocalizations.of(context).moreMeasurementEntries,
|
||||
|
||||
@@ -4891,8 +4891,39 @@ class $MeasurementCategoryTableTable extends MeasurementCategoryTable
|
||||
).withConverter<MetricType>(
|
||||
$MeasurementCategoryTableTable.$convertermetricType,
|
||||
);
|
||||
static const VerificationMeta _parentIdMeta = const VerificationMeta(
|
||||
'parentId',
|
||||
);
|
||||
@override
|
||||
List<GeneratedColumn> get $columns => [id, name, unit, metricType];
|
||||
late final GeneratedColumn<String> parentId = GeneratedColumn<String>(
|
||||
'parent_id',
|
||||
aliasedName,
|
||||
true,
|
||||
type: DriftSqlType.string,
|
||||
requiredDuringInsert: false,
|
||||
defaultConstraints: GeneratedColumn.constraintIsAlways(
|
||||
'REFERENCES measurements_category (id)',
|
||||
),
|
||||
);
|
||||
static const VerificationMeta _orderMeta = const VerificationMeta('order');
|
||||
@override
|
||||
late final GeneratedColumn<int> order = GeneratedColumn<int>(
|
||||
'order',
|
||||
aliasedName,
|
||||
false,
|
||||
type: DriftSqlType.int,
|
||||
requiredDuringInsert: false,
|
||||
defaultValue: const Constant(0),
|
||||
);
|
||||
@override
|
||||
List<GeneratedColumn> get $columns => [
|
||||
id,
|
||||
name,
|
||||
unit,
|
||||
metricType,
|
||||
parentId,
|
||||
order,
|
||||
];
|
||||
@override
|
||||
String get aliasedName => _alias ?? actualTableName;
|
||||
@override
|
||||
@@ -4924,6 +4955,18 @@ class $MeasurementCategoryTableTable extends MeasurementCategoryTable
|
||||
} else if (isInserting) {
|
||||
context.missing(_unitMeta);
|
||||
}
|
||||
if (data.containsKey('parent_id')) {
|
||||
context.handle(
|
||||
_parentIdMeta,
|
||||
parentId.isAcceptableOrUnknown(data['parent_id']!, _parentIdMeta),
|
||||
);
|
||||
}
|
||||
if (data.containsKey('order')) {
|
||||
context.handle(
|
||||
_orderMeta,
|
||||
order.isAcceptableOrUnknown(data['order']!, _orderMeta),
|
||||
);
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
@@ -4951,6 +4994,14 @@ class $MeasurementCategoryTableTable extends MeasurementCategoryTable
|
||||
data['${effectivePrefix}metric_type'],
|
||||
)!,
|
||||
),
|
||||
parentId: attachedDatabase.typeMapping.read(
|
||||
DriftSqlType.string,
|
||||
data['${effectivePrefix}parent_id'],
|
||||
),
|
||||
order: attachedDatabase.typeMapping.read(
|
||||
DriftSqlType.int,
|
||||
data['${effectivePrefix}order'],
|
||||
)!,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4968,12 +5019,16 @@ class MeasurementCategoryTableCompanion extends UpdateCompanion<MeasurementCateg
|
||||
final Value<String> name;
|
||||
final Value<String> unit;
|
||||
final Value<MetricType> metricType;
|
||||
final Value<String?> parentId;
|
||||
final Value<int> order;
|
||||
final Value<int> rowid;
|
||||
const MeasurementCategoryTableCompanion({
|
||||
this.id = const Value.absent(),
|
||||
this.name = const Value.absent(),
|
||||
this.unit = const Value.absent(),
|
||||
this.metricType = const Value.absent(),
|
||||
this.parentId = const Value.absent(),
|
||||
this.order = const Value.absent(),
|
||||
this.rowid = const Value.absent(),
|
||||
});
|
||||
MeasurementCategoryTableCompanion.insert({
|
||||
@@ -4981,6 +5036,8 @@ class MeasurementCategoryTableCompanion extends UpdateCompanion<MeasurementCateg
|
||||
required String name,
|
||||
required String unit,
|
||||
required MetricType metricType,
|
||||
this.parentId = const Value.absent(),
|
||||
this.order = const Value.absent(),
|
||||
this.rowid = const Value.absent(),
|
||||
}) : name = Value(name),
|
||||
unit = Value(unit),
|
||||
@@ -4990,6 +5047,8 @@ class MeasurementCategoryTableCompanion extends UpdateCompanion<MeasurementCateg
|
||||
Expression<String>? name,
|
||||
Expression<String>? unit,
|
||||
Expression<String>? metricType,
|
||||
Expression<String>? parentId,
|
||||
Expression<int>? order,
|
||||
Expression<int>? rowid,
|
||||
}) {
|
||||
return RawValuesInsertable({
|
||||
@@ -4997,6 +5056,8 @@ class MeasurementCategoryTableCompanion extends UpdateCompanion<MeasurementCateg
|
||||
if (name != null) 'name': name,
|
||||
if (unit != null) 'unit': unit,
|
||||
if (metricType != null) 'metric_type': metricType,
|
||||
if (parentId != null) 'parent_id': parentId,
|
||||
if (order != null) 'order': order,
|
||||
if (rowid != null) 'rowid': rowid,
|
||||
});
|
||||
}
|
||||
@@ -5006,6 +5067,8 @@ class MeasurementCategoryTableCompanion extends UpdateCompanion<MeasurementCateg
|
||||
Value<String>? name,
|
||||
Value<String>? unit,
|
||||
Value<MetricType>? metricType,
|
||||
Value<String?>? parentId,
|
||||
Value<int>? order,
|
||||
Value<int>? rowid,
|
||||
}) {
|
||||
return MeasurementCategoryTableCompanion(
|
||||
@@ -5013,6 +5076,8 @@ class MeasurementCategoryTableCompanion extends UpdateCompanion<MeasurementCateg
|
||||
name: name ?? this.name,
|
||||
unit: unit ?? this.unit,
|
||||
metricType: metricType ?? this.metricType,
|
||||
parentId: parentId ?? this.parentId,
|
||||
order: order ?? this.order,
|
||||
rowid: rowid ?? this.rowid,
|
||||
);
|
||||
}
|
||||
@@ -5036,6 +5101,12 @@ class MeasurementCategoryTableCompanion extends UpdateCompanion<MeasurementCateg
|
||||
),
|
||||
);
|
||||
}
|
||||
if (parentId.present) {
|
||||
map['parent_id'] = Variable<String>(parentId.value);
|
||||
}
|
||||
if (order.present) {
|
||||
map['order'] = Variable<int>(order.value);
|
||||
}
|
||||
if (rowid.present) {
|
||||
map['rowid'] = Variable<int>(rowid.value);
|
||||
}
|
||||
@@ -5049,6 +5120,8 @@ class MeasurementCategoryTableCompanion extends UpdateCompanion<MeasurementCateg
|
||||
..write('name: $name, ')
|
||||
..write('unit: $unit, ')
|
||||
..write('metricType: $metricType, ')
|
||||
..write('parentId: $parentId, ')
|
||||
..write('order: $order, ')
|
||||
..write('rowid: $rowid')
|
||||
..write(')'))
|
||||
.toString();
|
||||
@@ -16476,6 +16549,8 @@ typedef $$MeasurementCategoryTableTableCreateCompanionBuilder =
|
||||
required String name,
|
||||
required String unit,
|
||||
required MetricType metricType,
|
||||
Value<String?> parentId,
|
||||
Value<int> order,
|
||||
Value<int> rowid,
|
||||
});
|
||||
typedef $$MeasurementCategoryTableTableUpdateCompanionBuilder =
|
||||
@@ -16484,6 +16559,8 @@ typedef $$MeasurementCategoryTableTableUpdateCompanionBuilder =
|
||||
Value<String> name,
|
||||
Value<String> unit,
|
||||
Value<MetricType> metricType,
|
||||
Value<String?> parentId,
|
||||
Value<int> order,
|
||||
Value<int> rowid,
|
||||
});
|
||||
|
||||
@@ -16500,6 +16577,26 @@ final class $$MeasurementCategoryTableTableReferences
|
||||
super.$_typedResult,
|
||||
);
|
||||
|
||||
static $MeasurementCategoryTableTable _parentIdTable(
|
||||
_$DriftPowersyncDatabase db,
|
||||
) => db.measurementCategoryTable.createAlias(
|
||||
'measurements_category__parent_id__measurements_category__id',
|
||||
);
|
||||
|
||||
$$MeasurementCategoryTableTableProcessedTableManager? get parentId {
|
||||
final $_column = $_itemColumn<String>('parent_id');
|
||||
if ($_column == null) return null;
|
||||
final manager = $$MeasurementCategoryTableTableTableManager(
|
||||
$_db,
|
||||
$_db.measurementCategoryTable,
|
||||
).filter((f) => f.id.sqlEquals($_column));
|
||||
final item = $_typedResult.readTableOrNull(_parentIdTable($_db));
|
||||
if (item == null) return manager;
|
||||
return ProcessedTableManager(
|
||||
manager.$state.copyWith(prefetchedData: [item]),
|
||||
);
|
||||
}
|
||||
|
||||
static MultiTypedResultKey<$MeasurementEntryTableTable, List<MeasurementEntry>>
|
||||
_measurementEntryTableRefsTable(_$DriftPowersyncDatabase db) => MultiTypedResultKey.fromTable(
|
||||
db.measurementEntryTable,
|
||||
@@ -16551,6 +16648,33 @@ class $$MeasurementCategoryTableTableFilterComposer
|
||||
builder: (column) => ColumnWithTypeConverterFilters(column),
|
||||
);
|
||||
|
||||
ColumnFilters<int> get order => $composableBuilder(
|
||||
column: $table.order,
|
||||
builder: (column) => ColumnFilters(column),
|
||||
);
|
||||
|
||||
$$MeasurementCategoryTableTableFilterComposer get parentId {
|
||||
final $$MeasurementCategoryTableTableFilterComposer composer = $composerBuilder(
|
||||
composer: this,
|
||||
getCurrentColumn: (t) => t.parentId,
|
||||
referencedTable: $db.measurementCategoryTable,
|
||||
getReferencedColumn: (t) => t.id,
|
||||
builder:
|
||||
(
|
||||
joinBuilder, {
|
||||
$addJoinBuilderToRootComposer,
|
||||
$removeJoinBuilderFromRootComposer,
|
||||
}) => $$MeasurementCategoryTableTableFilterComposer(
|
||||
$db: $db,
|
||||
$table: $db.measurementCategoryTable,
|
||||
$addJoinBuilderToRootComposer: $addJoinBuilderToRootComposer,
|
||||
joinBuilder: joinBuilder,
|
||||
$removeJoinBuilderFromRootComposer: $removeJoinBuilderFromRootComposer,
|
||||
),
|
||||
);
|
||||
return composer;
|
||||
}
|
||||
|
||||
Expression<bool> measurementEntryTableRefs(
|
||||
Expression<bool> Function($$MeasurementEntryTableTableFilterComposer f) f,
|
||||
) {
|
||||
@@ -16604,6 +16728,33 @@ class $$MeasurementCategoryTableTableOrderingComposer
|
||||
column: $table.metricType,
|
||||
builder: (column) => ColumnOrderings(column),
|
||||
);
|
||||
|
||||
ColumnOrderings<int> get order => $composableBuilder(
|
||||
column: $table.order,
|
||||
builder: (column) => ColumnOrderings(column),
|
||||
);
|
||||
|
||||
$$MeasurementCategoryTableTableOrderingComposer get parentId {
|
||||
final $$MeasurementCategoryTableTableOrderingComposer composer = $composerBuilder(
|
||||
composer: this,
|
||||
getCurrentColumn: (t) => t.parentId,
|
||||
referencedTable: $db.measurementCategoryTable,
|
||||
getReferencedColumn: (t) => t.id,
|
||||
builder:
|
||||
(
|
||||
joinBuilder, {
|
||||
$addJoinBuilderToRootComposer,
|
||||
$removeJoinBuilderFromRootComposer,
|
||||
}) => $$MeasurementCategoryTableTableOrderingComposer(
|
||||
$db: $db,
|
||||
$table: $db.measurementCategoryTable,
|
||||
$addJoinBuilderToRootComposer: $addJoinBuilderToRootComposer,
|
||||
joinBuilder: joinBuilder,
|
||||
$removeJoinBuilderFromRootComposer: $removeJoinBuilderFromRootComposer,
|
||||
),
|
||||
);
|
||||
return composer;
|
||||
}
|
||||
}
|
||||
|
||||
class $$MeasurementCategoryTableTableAnnotationComposer
|
||||
@@ -16629,6 +16780,31 @@ class $$MeasurementCategoryTableTableAnnotationComposer
|
||||
builder: (column) => column,
|
||||
);
|
||||
|
||||
GeneratedColumn<int> get order =>
|
||||
$composableBuilder(column: $table.order, builder: (column) => column);
|
||||
|
||||
$$MeasurementCategoryTableTableAnnotationComposer get parentId {
|
||||
final $$MeasurementCategoryTableTableAnnotationComposer composer = $composerBuilder(
|
||||
composer: this,
|
||||
getCurrentColumn: (t) => t.parentId,
|
||||
referencedTable: $db.measurementCategoryTable,
|
||||
getReferencedColumn: (t) => t.id,
|
||||
builder:
|
||||
(
|
||||
joinBuilder, {
|
||||
$addJoinBuilderToRootComposer,
|
||||
$removeJoinBuilderFromRootComposer,
|
||||
}) => $$MeasurementCategoryTableTableAnnotationComposer(
|
||||
$db: $db,
|
||||
$table: $db.measurementCategoryTable,
|
||||
$addJoinBuilderToRootComposer: $addJoinBuilderToRootComposer,
|
||||
joinBuilder: joinBuilder,
|
||||
$removeJoinBuilderFromRootComposer: $removeJoinBuilderFromRootComposer,
|
||||
),
|
||||
);
|
||||
return composer;
|
||||
}
|
||||
|
||||
Expression<T> measurementEntryTableRefs<T extends Object>(
|
||||
Expression<T> Function($$MeasurementEntryTableTableAnnotationComposer a) f,
|
||||
) {
|
||||
@@ -16667,7 +16843,10 @@ class $$MeasurementCategoryTableTableTableManager
|
||||
$$MeasurementCategoryTableTableUpdateCompanionBuilder,
|
||||
(MeasurementCategory, $$MeasurementCategoryTableTableReferences),
|
||||
MeasurementCategory,
|
||||
PrefetchHooks Function({bool measurementEntryTableRefs})
|
||||
PrefetchHooks Function({
|
||||
bool parentId,
|
||||
bool measurementEntryTableRefs,
|
||||
})
|
||||
> {
|
||||
$$MeasurementCategoryTableTableTableManager(
|
||||
_$DriftPowersyncDatabase db,
|
||||
@@ -16694,12 +16873,16 @@ class $$MeasurementCategoryTableTableTableManager
|
||||
Value<String> name = const Value.absent(),
|
||||
Value<String> unit = const Value.absent(),
|
||||
Value<MetricType> metricType = const Value.absent(),
|
||||
Value<String?> parentId = const Value.absent(),
|
||||
Value<int> order = const Value.absent(),
|
||||
Value<int> rowid = const Value.absent(),
|
||||
}) => MeasurementCategoryTableCompanion(
|
||||
id: id,
|
||||
name: name,
|
||||
unit: unit,
|
||||
metricType: metricType,
|
||||
parentId: parentId,
|
||||
order: order,
|
||||
rowid: rowid,
|
||||
),
|
||||
createCompanionCallback:
|
||||
@@ -16708,12 +16891,16 @@ class $$MeasurementCategoryTableTableTableManager
|
||||
required String name,
|
||||
required String unit,
|
||||
required MetricType metricType,
|
||||
Value<String?> parentId = const Value.absent(),
|
||||
Value<int> order = const Value.absent(),
|
||||
Value<int> rowid = const Value.absent(),
|
||||
}) => MeasurementCategoryTableCompanion.insert(
|
||||
id: id,
|
||||
name: name,
|
||||
unit: unit,
|
||||
metricType: metricType,
|
||||
parentId: parentId,
|
||||
order: order,
|
||||
rowid: rowid,
|
||||
),
|
||||
withReferenceMapper: (p0) => p0
|
||||
@@ -16724,13 +16911,44 @@ class $$MeasurementCategoryTableTableTableManager
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
prefetchHooksCallback: ({measurementEntryTableRefs = false}) {
|
||||
prefetchHooksCallback: ({parentId = false, measurementEntryTableRefs = false}) {
|
||||
return PrefetchHooks(
|
||||
db: db,
|
||||
explicitlyWatchedTables: [
|
||||
if (measurementEntryTableRefs) db.measurementEntryTable,
|
||||
],
|
||||
addJoins: null,
|
||||
addJoins:
|
||||
<
|
||||
T extends TableManagerState<
|
||||
dynamic,
|
||||
dynamic,
|
||||
dynamic,
|
||||
dynamic,
|
||||
dynamic,
|
||||
dynamic,
|
||||
dynamic,
|
||||
dynamic,
|
||||
dynamic,
|
||||
dynamic,
|
||||
dynamic
|
||||
>
|
||||
>(state) {
|
||||
if (parentId) {
|
||||
state =
|
||||
state.withJoin(
|
||||
currentTable: table,
|
||||
currentColumn: table.parentId,
|
||||
referencedTable: $$MeasurementCategoryTableTableReferences
|
||||
._parentIdTable(db),
|
||||
referencedColumn: $$MeasurementCategoryTableTableReferences
|
||||
._parentIdTable(db)
|
||||
.id,
|
||||
)
|
||||
as T;
|
||||
}
|
||||
|
||||
return state;
|
||||
},
|
||||
getPrefetchedDataCallback: (items) async {
|
||||
return [
|
||||
if (measurementEntryTableRefs)
|
||||
@@ -16748,7 +16966,9 @@ class $$MeasurementCategoryTableTableTableManager
|
||||
p0,
|
||||
).measurementEntryTableRefs,
|
||||
referencedItemsForCurrentItem: (item, referencedItems) =>
|
||||
referencedItems.where((e) => e.categoryId == item.id),
|
||||
referencedItems.where(
|
||||
(e) => e.categoryId == item.id,
|
||||
),
|
||||
typedResults: items,
|
||||
),
|
||||
];
|
||||
@@ -16771,7 +16991,7 @@ typedef $$MeasurementCategoryTableTableProcessedTableManager =
|
||||
$$MeasurementCategoryTableTableUpdateCompanionBuilder,
|
||||
(MeasurementCategory, $$MeasurementCategoryTableTableReferences),
|
||||
MeasurementCategory,
|
||||
PrefetchHooks Function({bool measurementEntryTableRefs})
|
||||
PrefetchHooks Function({bool parentId, bool measurementEntryTableRefs})
|
||||
>;
|
||||
typedef $$MeasurementEntryTableTableCreateCompanionBuilder =
|
||||
MeasurementEntryTableCompanion Function({
|
||||
|
||||
@@ -34,7 +34,14 @@ class MeasurementCategoryTable extends Table {
|
||||
TextColumn get unit => text()();
|
||||
TextColumn get metricType =>
|
||||
text().named('metric_type').map(const MeasurementMetricTypeConverter())();
|
||||
IntColumn get order => integer().nullable()();
|
||||
|
||||
/// Multi-value groups: parent category id (max. one level of nesting; only
|
||||
/// leaf categories carry entries).
|
||||
TextColumn get parentId =>
|
||||
text().named('parent_id').nullable().references(MeasurementCategoryTable, #id)();
|
||||
|
||||
/// Position in the category list; for children, the position within the group
|
||||
IntColumn get order => integer().withDefault(const Constant(0))();
|
||||
}
|
||||
|
||||
const PowersyncMeasurementCategoryTable = ps.Table(
|
||||
@@ -43,8 +50,12 @@ const PowersyncMeasurementCategoryTable = ps.Table(
|
||||
ps.Column.text('name'),
|
||||
ps.Column.text('unit'),
|
||||
ps.Column.text('metric_type'),
|
||||
ps.Column.text('parent_id'),
|
||||
ps.Column.integer('order'),
|
||||
],
|
||||
indexes: [
|
||||
ps.Index('parent_idx', [ps.IndexedColumn('parent_id')]),
|
||||
],
|
||||
);
|
||||
|
||||
@UseRowClass(MeasurementEntry)
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import 'package:health/health.dart';
|
||||
import 'package:health_bridge/health.dart';
|
||||
import 'package:wger/features/measurements/models/measurement_category.dart';
|
||||
|
||||
/// A body metric that can be imported from Apple Health / Health Connect into a
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import 'package:health/health.dart';
|
||||
import 'package:health_bridge/health.dart';
|
||||
|
||||
/// A single reading pulled from a health platform, reduced to the fields the
|
||||
/// importer needs. Keeps the `health` package's [HealthDataPoint] out of the
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:health/health.dart';
|
||||
import 'package:health_bridge/health.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:wger/features/health/models/health_reading.dart';
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
*/
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:health/health.dart';
|
||||
import 'package:health_bridge/health.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:powersync/powersync.dart' as ps;
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
@@ -103,18 +103,36 @@ class MeasurementCategory with _$MeasurementCategory {
|
||||
@override
|
||||
final MetricType metricType;
|
||||
|
||||
/// Multi-value groups (e.g. blood pressure): id of the parent category, one
|
||||
/// child per component. Max. one level of nesting; only leaf categories
|
||||
/// (no children) carry entries.
|
||||
@override
|
||||
final String? parentId;
|
||||
|
||||
/// Position in the category list; for children, the position within the group
|
||||
@override
|
||||
final int order;
|
||||
|
||||
/// Child categories (components) of this group. Populated by the repository
|
||||
/// for display, never persisted directly.
|
||||
@override
|
||||
final List<MeasurementCategory> children;
|
||||
|
||||
MeasurementCategory({
|
||||
this.id,
|
||||
this.name = '',
|
||||
this.unit = '',
|
||||
this.entries = const [],
|
||||
this.metricType = MetricType.custom,
|
||||
this.parentId,
|
||||
this.order = 0,
|
||||
this.children = const [],
|
||||
});
|
||||
|
||||
/// `true` for group parents (blood pressure etc.), which hold no entries of
|
||||
/// their own
|
||||
bool get isGroup => children.isNotEmpty;
|
||||
|
||||
MeasurementEntry findEntryById(String id) {
|
||||
return entries.firstWhere(
|
||||
(entry) => entry.id == id,
|
||||
@@ -129,6 +147,7 @@ class MeasurementCategory with _$MeasurementCategory {
|
||||
name: Value(name),
|
||||
unit: Value(unit),
|
||||
metricType: Value(metricType),
|
||||
parentId: Value(parentId),
|
||||
order: Value(order),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,13 @@ mixin _$MeasurementCategory {
|
||||
/// Client-generated UUID, is `null` only before the first persist
|
||||
String? get id; String get name; String get unit; List<MeasurementEntry> get entries;/// Drives the health-platform mapping (and, later, default unit/aggregation/
|
||||
/// chart). [MetricType.custom] for plain user-created categories.
|
||||
MetricType get metricType;
|
||||
MetricType get metricType;/// Multi-value groups (e.g. blood pressure): id of the parent category, one
|
||||
/// child per component. Max. one level of nesting; only leaf categories
|
||||
/// (no children) carry entries.
|
||||
String? get parentId;/// Position in the category list; for children, the position within the group
|
||||
int get order;/// Child categories (components) of this group. Populated by the repository
|
||||
/// for display, never persisted directly.
|
||||
List<MeasurementCategory> get children;
|
||||
/// Create a copy of MeasurementCategory
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@@ -28,16 +34,16 @@ $MeasurementCategoryCopyWith<MeasurementCategory> get copyWith => _$MeasurementC
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is MeasurementCategory&&(identical(other.id, id) || other.id == id)&&(identical(other.name, name) || other.name == name)&&(identical(other.unit, unit) || other.unit == unit)&&const DeepCollectionEquality().equals(other.entries, entries)&&(identical(other.metricType, metricType) || other.metricType == metricType));
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is MeasurementCategory&&(identical(other.id, id) || other.id == id)&&(identical(other.name, name) || other.name == name)&&(identical(other.unit, unit) || other.unit == unit)&&const DeepCollectionEquality().equals(other.entries, entries)&&(identical(other.metricType, metricType) || other.metricType == metricType)&&(identical(other.parentId, parentId) || other.parentId == parentId)&&(identical(other.order, order) || other.order == order)&&const DeepCollectionEquality().equals(other.children, children));
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType,id,name,unit,const DeepCollectionEquality().hash(entries),metricType);
|
||||
int get hashCode => Object.hash(runtimeType,id,name,unit,const DeepCollectionEquality().hash(entries),metricType,parentId,order,const DeepCollectionEquality().hash(children));
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'MeasurementCategory(id: $id, name: $name, unit: $unit, entries: $entries, metricType: $metricType)';
|
||||
return 'MeasurementCategory(id: $id, name: $name, unit: $unit, entries: $entries, metricType: $metricType, parentId: $parentId, order: $order, children: $children)';
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +54,7 @@ abstract mixin class $MeasurementCategoryCopyWith<$Res> {
|
||||
factory $MeasurementCategoryCopyWith(MeasurementCategory value, $Res Function(MeasurementCategory) _then) = _$MeasurementCategoryCopyWithImpl;
|
||||
@useResult
|
||||
$Res call({
|
||||
String? id, String name, String unit, List<MeasurementEntry> entries, MetricType metricType
|
||||
String? id, String name, String unit, List<MeasurementEntry> entries, MetricType metricType, String? parentId, int order, List<MeasurementCategory> children
|
||||
});
|
||||
|
||||
|
||||
@@ -65,14 +71,17 @@ class _$MeasurementCategoryCopyWithImpl<$Res>
|
||||
|
||||
/// Create a copy of MeasurementCategory
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline') @override $Res call({Object? id = freezed,Object? name = null,Object? unit = null,Object? entries = null,Object? metricType = null,}) {
|
||||
@pragma('vm:prefer-inline') @override $Res call({Object? id = freezed,Object? name = null,Object? unit = null,Object? entries = null,Object? metricType = null,Object? parentId = freezed,Object? order = null,Object? children = null,}) {
|
||||
return _then(MeasurementCategory(
|
||||
id: freezed == id ? _self.id : id // ignore: cast_nullable_to_non_nullable
|
||||
as String?,name: null == name ? _self.name : name // ignore: cast_nullable_to_non_nullable
|
||||
as String,unit: null == unit ? _self.unit : unit // ignore: cast_nullable_to_non_nullable
|
||||
as String,entries: null == entries ? _self.entries : entries // ignore: cast_nullable_to_non_nullable
|
||||
as List<MeasurementEntry>,metricType: null == metricType ? _self.metricType : metricType // ignore: cast_nullable_to_non_nullable
|
||||
as MetricType,
|
||||
as MetricType,parentId: freezed == parentId ? _self.parentId : parentId // ignore: cast_nullable_to_non_nullable
|
||||
as String?,order: null == order ? _self.order : order // ignore: cast_nullable_to_non_nullable
|
||||
as int,children: null == children ? _self.children : children // ignore: cast_nullable_to_non_nullable
|
||||
as List<MeasurementCategory>,
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
@@ -72,6 +72,12 @@ final class MeasurementNotifier extends _$MeasurementNotifier {
|
||||
await _repo.addLocalDrift(entry);
|
||||
}
|
||||
|
||||
/// Adds one reading of a multi-value group (one entry per component,
|
||||
/// persisted atomically).
|
||||
Future<void> addGroupEntries(List<MeasurementEntry> entries) async {
|
||||
await _repo.addLocalDriftGroupEntries(entries);
|
||||
}
|
||||
|
||||
// --- MeasurementCategory operations (delegated to repository) ---
|
||||
Future<void> deleteCategory(String id) async {
|
||||
await _repo.deleteLocalDriftCategory(id);
|
||||
|
||||
@@ -33,7 +33,7 @@ final class MeasurementNotifierProvider
|
||||
MeasurementNotifier create() => MeasurementNotifier();
|
||||
}
|
||||
|
||||
String _$measurementNotifierHash() => r'94978ed841f94d3481322dc144ef82da95cfb62c';
|
||||
String _$measurementNotifierHash() => r'397b6739b5d49e226b1ca3bb1837b2f16c55e0f7';
|
||||
|
||||
abstract class _$MeasurementNotifier extends $StreamNotifier<List<MeasurementCategory>> {
|
||||
Stream<List<MeasurementCategory>> build();
|
||||
|
||||
@@ -39,7 +39,11 @@ class MeasurementRepository {
|
||||
|
||||
MeasurementRepository(this._db);
|
||||
|
||||
/// Watches all categories, populated with their appropriate entries
|
||||
/// Watches all categories, populated with their appropriate entries.
|
||||
///
|
||||
/// The list is flat (children of multi-value groups appear as regular items
|
||||
/// with a non-null `parentId`), but group parents additionally get their
|
||||
/// [MeasurementCategory.children] attached, sorted by their in-group order.
|
||||
Stream<List<MeasurementCategory>> watchAll() {
|
||||
_logger.finer('Watching all measurement categories with entries');
|
||||
|
||||
@@ -72,9 +76,16 @@ class MeasurementRepository {
|
||||
}
|
||||
}
|
||||
|
||||
return map.values
|
||||
final categories = map.values
|
||||
.map((c) => c.copyWith(entries: List<MeasurementEntry>.from(c.entries)))
|
||||
.toList();
|
||||
|
||||
// Attach children to their group parents (rows are already sorted by
|
||||
// order/name, so insertion order is the display order).
|
||||
return categories.map((c) {
|
||||
final children = categories.where((other) => other.parentId == c.id).toList();
|
||||
return children.isEmpty ? c : c.copyWith(children: children);
|
||||
}).toList();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -103,10 +114,26 @@ class MeasurementRepository {
|
||||
await _db.into(_db.measurementEntryTable).insert(entry.toCompanion());
|
||||
}
|
||||
|
||||
/// Inserts one reading of a multi-value group: one entry per component,
|
||||
/// written in a single transaction so a reading is never half-persisted.
|
||||
Future<void> addLocalDriftGroupEntries(List<MeasurementEntry> entries) async {
|
||||
_logger.finer('Adding ${entries.length} local measurement entries for a group reading');
|
||||
await _db.transaction(() async {
|
||||
for (final entry in entries) {
|
||||
await _db.into(_db.measurementEntryTable).insert(entry.toCompanion());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Categories
|
||||
Future<void> deleteLocalDriftCategory(String id) async {
|
||||
_logger.finer('Deleting local measurement category $id');
|
||||
await (_db.delete(_db.measurementCategoryTable)..where((t) => t.id.equals(id))).go();
|
||||
await _db.transaction(() async {
|
||||
// Children of a multi-value group are meaningless without their parent;
|
||||
// the server cascades the same way.
|
||||
await (_db.delete(_db.measurementCategoryTable)..where((t) => t.parentId.equals(id))).go();
|
||||
await (_db.delete(_db.measurementCategoryTable)..where((t) => t.id.equals(id))).go();
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> updateLocalDriftCategory(MeasurementCategory category) async {
|
||||
|
||||
@@ -31,11 +31,17 @@ class CategoriesList extends ConsumerWidget {
|
||||
return AsyncValueWidget<List<MeasurementCategory>>(
|
||||
value: ref.watch(measurementProvider),
|
||||
loggerName: 'CategoriesList',
|
||||
data: (categoriesList) => ListView.builder(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
itemCount: categoriesList.length,
|
||||
itemBuilder: (context, index) => CategoriesCard(categoriesList[index]),
|
||||
),
|
||||
data: (categoriesList) {
|
||||
// Children of multi-value groups are rendered inside their parent's
|
||||
// card, not as own list items
|
||||
final topLevel = categoriesList.where((c) => c.parentId == null).toList();
|
||||
|
||||
return ListView.builder(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
itemCount: topLevel.length,
|
||||
itemBuilder: (context, index) => CategoriesCard(topLevel[index]),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:wger/core/form_screen.dart';
|
||||
import 'package:wger/features/measurements/models/measurement_category.dart';
|
||||
@@ -34,6 +35,10 @@ class CategoriesCard extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (currentCategory.isGroup) {
|
||||
return _buildGroupCard(context);
|
||||
}
|
||||
|
||||
// sensibleRange() operates on raw (pre-aggregation) entries
|
||||
final (entriesAll, entries7dAvg) = sensibleRange(
|
||||
currentCategory.entries.map((e) => MeasurementChartEntry(e.value, e.date)).toList(),
|
||||
@@ -115,4 +120,62 @@ class CategoriesCard extends StatelessWidget {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Card for a multi-value group (e.g. blood pressure): one row per
|
||||
/// component with its latest reading; new readings are entered for all
|
||||
/// components at once.
|
||||
Widget _buildGroupCard(BuildContext context) {
|
||||
return Card(
|
||||
elevation: elevation,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
|
||||
child: Text(
|
||||
currentCategory.name,
|
||||
style: Theme.of(context).textTheme.titleLarge,
|
||||
textAlign: TextAlign.center,
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
...currentCategory.children.map((child) {
|
||||
// Entries arrive sorted by date descending, so first is the latest
|
||||
final latest = child.entries.firstOrNull;
|
||||
return ListTile(
|
||||
dense: true,
|
||||
title: Text(child.name),
|
||||
trailing: Text(
|
||||
latest != null ? '${latest.value} ${child.unit}' : '—',
|
||||
style: Theme.of(context).textTheme.bodyLarge,
|
||||
),
|
||||
onTap: () => Navigator.pushNamed(
|
||||
context,
|
||||
MeasurementEntriesScreen.routeName,
|
||||
arguments: child.id,
|
||||
),
|
||||
);
|
||||
}),
|
||||
const Divider(),
|
||||
Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: IconButton(
|
||||
onPressed: () async {
|
||||
await Navigator.pushNamed(
|
||||
context,
|
||||
FormScreen.routeName,
|
||||
arguments: FormScreenArguments(
|
||||
AppLocalizations.of(context).newEntry,
|
||||
GroupMeasurementEntryForm(currentCategory),
|
||||
),
|
||||
);
|
||||
},
|
||||
icon: const Icon(Icons.add),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,6 +111,53 @@ class _MeasurementCategoryFormState extends ConsumerState<MeasurementCategoryFor
|
||||
}
|
||||
},
|
||||
),
|
||||
|
||||
// Parent group (multi-value measurements, e.g. blood pressure).
|
||||
// Mirrors the server rules: only top-level, entry-free categories
|
||||
// can be parents, and a category with children cannot be nested.
|
||||
Builder(
|
||||
builder: (context) {
|
||||
final categories = ref.watch(measurementProvider).asData?.value ?? [];
|
||||
|
||||
final hasChildren =
|
||||
_draft.id != null && categories.any((c) => c.parentId == _draft.id);
|
||||
if (hasChildren) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
final candidates = categories
|
||||
.where((c) => c.parentId == null && c.id != _draft.id && c.entries.isEmpty)
|
||||
.toList();
|
||||
if (candidates.isEmpty) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
final initialParent = candidates.any((c) => c.id == _draft.parentId)
|
||||
? _draft.parentId
|
||||
: null;
|
||||
|
||||
return DropdownButtonFormField<String?>(
|
||||
initialValue: initialParent,
|
||||
decoration: InputDecoration(
|
||||
labelText: AppLocalizations.of(context).partOfGroup,
|
||||
),
|
||||
items: [
|
||||
DropdownMenuItem<String?>(
|
||||
value: null,
|
||||
child: Text(AppLocalizations.of(context).noGroup),
|
||||
),
|
||||
...candidates.map(
|
||||
(c) => DropdownMenuItem<String?>(value: c.id, child: Text(c.name)),
|
||||
),
|
||||
],
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_draft = _draft.copyWith(parentId: value);
|
||||
});
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
FormSubmitButton(
|
||||
label: AppLocalizations.of(context).save,
|
||||
onPressed: () async {
|
||||
@@ -288,3 +335,97 @@ class _MeasurementEntryFormState extends ConsumerState<MeasurementEntryForm> {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Entry form for a multi-value group (e.g. blood pressure): one value field
|
||||
/// per component, saved as one entry per component with a shared timestamp.
|
||||
class GroupMeasurementEntryForm extends ConsumerStatefulWidget {
|
||||
final MeasurementCategory _group;
|
||||
|
||||
const GroupMeasurementEntryForm(this._group);
|
||||
|
||||
@override
|
||||
ConsumerState<GroupMeasurementEntryForm> createState() => _GroupMeasurementEntryFormState();
|
||||
}
|
||||
|
||||
class _GroupMeasurementEntryFormState extends ConsumerState<GroupMeasurementEntryForm> {
|
||||
final _form = GlobalKey<FormState>();
|
||||
|
||||
DateTime _date = DateTime.now();
|
||||
late final Map<String, num?> _values = {
|
||||
for (final child in widget._group.children) child.id!: null,
|
||||
};
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Form(
|
||||
key: _form,
|
||||
child: Column(
|
||||
children: [
|
||||
// Date and time are shared by all components of the reading
|
||||
DateInputWidget(
|
||||
value: _date,
|
||||
labelText: AppLocalizations.of(context).date,
|
||||
firstDate: DateTime(DateTime.now().year - 10),
|
||||
lastDate: DateTime.now(),
|
||||
onChanged: (date) {
|
||||
_date = _date.copyWith(
|
||||
year: date.year,
|
||||
month: date.month,
|
||||
day: date.day,
|
||||
);
|
||||
},
|
||||
),
|
||||
TimeInputWidget(
|
||||
value: TimeOfDay.fromDateTime(_date),
|
||||
labelText: AppLocalizations.of(context).time,
|
||||
onChanged: (time) {
|
||||
_date = _date.copyWith(
|
||||
hour: time.hour,
|
||||
minute: time.minute,
|
||||
second: 0,
|
||||
);
|
||||
},
|
||||
),
|
||||
|
||||
// One value field per component
|
||||
for (final child in widget._group.children)
|
||||
DecimalInputWidget(
|
||||
value: _values[child.id],
|
||||
labelText: child.name,
|
||||
suffixText: child.unit.isNotEmpty ? child.unit : widget._group.unit,
|
||||
isRequired: true,
|
||||
min: MeasurementEntry.minValue,
|
||||
max: MeasurementEntry.maxValue,
|
||||
onChanged: (value) => _values[child.id!] = value,
|
||||
),
|
||||
|
||||
FormSubmitButton(
|
||||
label: AppLocalizations.of(context).save,
|
||||
onPressed: () async {
|
||||
if (!_form.currentState!.validate()) {
|
||||
return;
|
||||
}
|
||||
_form.currentState!.save();
|
||||
|
||||
final entries = widget._group.children
|
||||
.map(
|
||||
(child) => MeasurementEntry(
|
||||
categoryId: child.id!,
|
||||
date: _date,
|
||||
value: _values[child.id]!,
|
||||
notes: '',
|
||||
),
|
||||
)
|
||||
.toList();
|
||||
await ref.read(measurementProvider.notifier).addGroupEntries(entries);
|
||||
|
||||
if (context.mounted) {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -592,6 +592,14 @@
|
||||
},
|
||||
"measurementEntriesHelpText": "The unit used to measure the category such as 'cm' or '%'",
|
||||
"@measurementEntriesHelpText": {},
|
||||
"partOfGroup": "Part of group",
|
||||
"@partOfGroup": {
|
||||
"description": "Dropdown label: makes a measurement category a component of a multi-value group (e.g. blood pressure)"
|
||||
},
|
||||
"noGroup": "No group",
|
||||
"@noGroup": {
|
||||
"description": "Dropdown option for a measurement category that is not part of any group"
|
||||
},
|
||||
"date": "Date",
|
||||
"@date": {
|
||||
"description": "The date of a workout log or body weight entry"
|
||||
|
||||
21
pubspec.lock
21
pubspec.lock
@@ -193,14 +193,6 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "5.1.2"
|
||||
carp_serializable:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: carp_serializable
|
||||
sha256: f039f8ea22e9437aef13fe7e9743c3761c76d401288dcb702eadd273c3e4dcef
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.0.1"
|
||||
change:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -743,14 +735,15 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.2.0"
|
||||
health:
|
||||
health_bridge:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: health
|
||||
sha256: "2d9e119f3a1d281139f93149b41032b9f80b759960875bc784c5a25dd3c17524"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "13.3.1"
|
||||
path: "."
|
||||
ref: "51a567db9a97ccb15a9c1138aa4bcbdaf3d6c7b1"
|
||||
resolved-ref: "51a567db9a97ccb15a9c1138aa4bcbdaf3d6c7b1"
|
||||
url: "https://github.com/ytsni/health_bridge.git"
|
||||
source: git
|
||||
version: "1.0.0"
|
||||
hooks:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
||||
10
pubspec.yaml
10
pubspec.yaml
@@ -51,7 +51,15 @@ dependencies:
|
||||
flutter_zxing: ^2.3.0
|
||||
font_awesome_flutter: ^11.0.0
|
||||
freezed_annotation: ^3.1.0
|
||||
health: ^13.3.1
|
||||
# Temporarily swap `health` with a fork with Swift Package Manager support.
|
||||
# Once that is available on upstream (see e.g. https://github.com/carp-dk/carp-health-flutter/issues/480 )
|
||||
# we can switch back. Note that if this doesn't happen in the near future we
|
||||
# can just re-activate the cocoapods infrastructure.
|
||||
# health: ^13.3.1
|
||||
health_bridge:
|
||||
git:
|
||||
url: https://github.com/ytsni/health_bridge.git
|
||||
ref: 51a567db9a97ccb15a9c1138aa4bcbdaf3d6c7b1
|
||||
http: ^1.6.0
|
||||
image_picker: ^1.2.2
|
||||
intl: ^0.20.2
|
||||
|
||||
@@ -2151,6 +2151,28 @@ class MockAppLocalizations extends _i1.Mock implements _i2.AppLocalizations {
|
||||
)
|
||||
as String);
|
||||
|
||||
@override
|
||||
String get partOfGroup =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.getter(#partOfGroup),
|
||||
returnValue: _i3.dummyValue<String>(
|
||||
this,
|
||||
Invocation.getter(#partOfGroup),
|
||||
),
|
||||
)
|
||||
as String);
|
||||
|
||||
@override
|
||||
String get noGroup =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.getter(#noGroup),
|
||||
returnValue: _i3.dummyValue<String>(
|
||||
this,
|
||||
Invocation.getter(#noGroup),
|
||||
),
|
||||
)
|
||||
as String);
|
||||
|
||||
@override
|
||||
String get date =>
|
||||
(super.noSuchMethod(
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:health/health.dart';
|
||||
import 'package:health_bridge/health.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:shared_preferences_platform_interface/in_memory_shared_preferences_async.dart';
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
// ignore_for_file: no_leading_underscores_for_library_prefixes
|
||||
import 'dart:async' as _i4;
|
||||
|
||||
import 'package:health/health.dart' as _i5;
|
||||
import 'package:health_bridge/health.dart' as _i5;
|
||||
import 'package:mockito/mockito.dart' as _i1;
|
||||
import 'package:mockito/src/dummies.dart' as _i3;
|
||||
import 'package:wger/features/health/models/health_reading.dart' as _i6;
|
||||
@@ -146,6 +146,17 @@ class MockMeasurementRepository extends _i1.Mock implements _i7.MeasurementRepos
|
||||
)
|
||||
as _i4.Future<void>);
|
||||
|
||||
@override
|
||||
_i4.Future<void> addLocalDriftGroupEntries(
|
||||
List<_i9.MeasurementEntry>? entries,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#addLocalDriftGroupEntries, [entries]),
|
||||
returnValue: _i4.Future<void>.value(),
|
||||
returnValueForMissingStub: _i4.Future<void>.value(),
|
||||
)
|
||||
as _i4.Future<void>);
|
||||
|
||||
@override
|
||||
_i4.Future<void> deleteLocalDriftCategory(String? id) =>
|
||||
(super.noSuchMethod(
|
||||
|
||||
@@ -88,6 +88,17 @@ class MockMeasurementRepository extends _i1.Mock implements _i2.MeasurementRepos
|
||||
)
|
||||
as _i3.Future<void>);
|
||||
|
||||
@override
|
||||
_i3.Future<void> addLocalDriftGroupEntries(
|
||||
List<_i5.MeasurementEntry>? entries,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#addLocalDriftGroupEntries, [entries]),
|
||||
returnValue: _i3.Future<void>.value(),
|
||||
returnValueForMissingStub: _i3.Future<void>.value(),
|
||||
)
|
||||
as _i3.Future<void>);
|
||||
|
||||
@override
|
||||
_i3.Future<void> deleteLocalDriftCategory(String? id) =>
|
||||
(super.noSuchMethod(
|
||||
|
||||
@@ -222,4 +222,69 @@ void main() {
|
||||
expect(emitted.map((c) => c.id), ['c2']);
|
||||
});
|
||||
});
|
||||
|
||||
group('multi-value groups', () {
|
||||
Future<void> seedBloodPressureGroup() async {
|
||||
await repo.addLocalDriftCategory(
|
||||
MeasurementCategory(id: 'bp', name: 'Blood pressure', unit: 'mmHg'),
|
||||
);
|
||||
await repo.addLocalDriftCategory(
|
||||
MeasurementCategory(id: 'sys', name: 'Systolic', unit: 'mmHg', parentId: 'bp', order: 0),
|
||||
);
|
||||
await repo.addLocalDriftCategory(
|
||||
MeasurementCategory(id: 'dia', name: 'Diastolic', unit: 'mmHg', parentId: 'bp', order: 1),
|
||||
);
|
||||
}
|
||||
|
||||
test('watchAll attaches children to their parent in group order', () async {
|
||||
await seedBloodPressureGroup();
|
||||
|
||||
final emitted = await repo.watchAll().first;
|
||||
|
||||
final parent = emitted.firstWhere((c) => c.id == 'bp');
|
||||
expect(parent.isGroup, isTrue);
|
||||
expect(parent.children.map((c) => c.id), ['sys', 'dia']);
|
||||
});
|
||||
|
||||
test('watchAll sorts categories by order before name', () async {
|
||||
await repo.addLocalDriftCategory(
|
||||
MeasurementCategory(id: 'c1', name: 'Aaa', unit: 'cm', order: 5),
|
||||
);
|
||||
await repo.addLocalDriftCategory(
|
||||
MeasurementCategory(id: 'c2', name: 'Zzz', unit: 'cm', order: 1),
|
||||
);
|
||||
|
||||
final emitted = await repo.watchAll().first;
|
||||
|
||||
expect(emitted.map((c) => c.id), ['c2', 'c1']);
|
||||
});
|
||||
|
||||
test('addLocalDriftGroupEntries inserts one entry per component', () async {
|
||||
await seedBloodPressureGroup();
|
||||
final date = DateTime.utc(2026, 7, 10, 14, 32);
|
||||
|
||||
await repo.addLocalDriftGroupEntries([
|
||||
MeasurementEntry(id: 'e1', categoryId: 'sys', date: date, value: 120, notes: ''),
|
||||
MeasurementEntry(id: 'e2', categoryId: 'dia', date: date, value: 80, notes: ''),
|
||||
]);
|
||||
|
||||
final emitted = await repo.watchAll().first;
|
||||
final parent = emitted.firstWhere((c) => c.id == 'bp');
|
||||
expect(parent.children.first.entries.single.value, 120);
|
||||
expect(parent.children.last.entries.single.value, 80);
|
||||
expect(
|
||||
parent.children.first.entries.single.date,
|
||||
parent.children.last.entries.single.date,
|
||||
);
|
||||
});
|
||||
|
||||
test('deleteLocalDriftCategory removes children along with the parent', () async {
|
||||
await seedBloodPressureGroup();
|
||||
|
||||
await repo.deleteLocalDriftCategory('bp');
|
||||
|
||||
final emitted = await repo.watchAll().first;
|
||||
expect(emitted, isEmpty);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -88,6 +88,17 @@ class MockMeasurementRepository extends _i1.Mock implements _i2.MeasurementRepos
|
||||
)
|
||||
as _i3.Future<void>);
|
||||
|
||||
@override
|
||||
_i3.Future<void> addLocalDriftGroupEntries(
|
||||
List<_i5.MeasurementEntry>? entries,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#addLocalDriftGroupEntries, [entries]),
|
||||
returnValue: _i3.Future<void>.value(),
|
||||
returnValueForMissingStub: _i3.Future<void>.value(),
|
||||
)
|
||||
as _i3.Future<void>);
|
||||
|
||||
@override
|
||||
_i3.Future<void> deleteLocalDriftCategory(String? id) =>
|
||||
(super.noSuchMethod(
|
||||
|
||||
@@ -97,6 +97,17 @@ class MockMeasurementRepository extends _i1.Mock implements _i2.MeasurementRepos
|
||||
)
|
||||
as _i3.Future<void>);
|
||||
|
||||
@override
|
||||
_i3.Future<void> addLocalDriftGroupEntries(
|
||||
List<_i5.MeasurementEntry>? entries,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#addLocalDriftGroupEntries, [entries]),
|
||||
returnValue: _i3.Future<void>.value(),
|
||||
returnValueForMissingStub: _i3.Future<void>.value(),
|
||||
)
|
||||
as _i3.Future<void>);
|
||||
|
||||
@override
|
||||
_i3.Future<void> deleteLocalDriftCategory(String? id) =>
|
||||
(super.noSuchMethod(
|
||||
|
||||
@@ -509,6 +509,17 @@ class MockMeasurementRepository extends _i1.Mock implements _i23.MeasurementRepo
|
||||
)
|
||||
as _i10.Future<void>);
|
||||
|
||||
@override
|
||||
_i10.Future<void> addLocalDriftGroupEntries(
|
||||
List<_i25.MeasurementEntry>? entries,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#addLocalDriftGroupEntries, [entries]),
|
||||
returnValue: _i10.Future<void>.value(),
|
||||
returnValueForMissingStub: _i10.Future<void>.value(),
|
||||
)
|
||||
as _i10.Future<void>);
|
||||
|
||||
@override
|
||||
_i10.Future<void> deleteLocalDriftCategory(String? id) =>
|
||||
(super.noSuchMethod(
|
||||
|
||||
@@ -88,6 +88,17 @@ class MockMeasurementRepository extends _i1.Mock implements _i2.MeasurementRepos
|
||||
)
|
||||
as _i3.Future<void>);
|
||||
|
||||
@override
|
||||
_i3.Future<void> addLocalDriftGroupEntries(
|
||||
List<_i5.MeasurementEntry>? entries,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#addLocalDriftGroupEntries, [entries]),
|
||||
returnValue: _i3.Future<void>.value(),
|
||||
returnValueForMissingStub: _i3.Future<void>.value(),
|
||||
)
|
||||
as _i3.Future<void>);
|
||||
|
||||
@override
|
||||
_i3.Future<void> deleteLocalDriftCategory(String? id) =>
|
||||
(super.noSuchMethod(
|
||||
|
||||
Reference in New Issue
Block a user