Fix source default, hide health settings section when unavailable

This commit is contained in:
Roland Geider
2026-07-11 01:37:19 +02:00
parent f0a088eb0e
commit 7ebb97c462
7 changed files with 47 additions and 31 deletions

View File

@@ -5192,7 +5192,7 @@ class $MeasurementEntryTableTable extends MeasurementEntryTable
false,
type: DriftSqlType.string,
requiredDuringInsert: false,
defaultValue: const Constant('manual'),
defaultValue: const Constant('user'),
);
static const VerificationMeta _externalIdMeta = const VerificationMeta(
'externalId',

View File

@@ -71,9 +71,9 @@ class MeasurementEntryTable extends Table {
RealColumn get value => real()();
TextColumn get notes => text()();
/// Where the reading came from: `manual` or a health platform
/// (`apple_health`, `health_connect`).
TextColumn get source => text().withDefault(const Constant('manual'))();
/// Where the reading came from; one of the server's `source` values:
/// `user` for manual entries or a health platform (`apple`, `google`).
TextColumn get source => text().withDefault(const Constant('user'))();
/// Platform record UUID, used to deduplicate re-imports. `null` for manual
/// entries.

View File

@@ -54,9 +54,6 @@ class SettingsPage extends StatelessWidget {
),
),
const SettingsDataPrivacy(),
ListTile(
title: Text(i18n.health, style: Theme.of(context).textTheme.headlineSmall),
),
const HealthSyncSettingsTile(),
ListTile(title: Text(i18n.others, style: Theme.of(context).textTheme.headlineSmall)),
const SettingsTheme(),

View File

@@ -47,7 +47,8 @@ class _HealthSyncSettingsTileState extends ConsumerState<HealthSyncSettingsTile>
@override
Widget build(BuildContext context) {
// Hide entirely if platform check hasn't completed or is unavailable
// Hide entirely (including the section header) if the platform check
// hasn't completed or no health platform is available
if (_isAvailable != true) {
return const SizedBox.shrink();
}
@@ -56,27 +57,34 @@ class _HealthSyncSettingsTileState extends ConsumerState<HealthSyncSettingsTile>
final i18n = AppLocalizations.of(context);
return SwitchListTile(
title: Text(i18n.healthSync),
subtitle: Text(i18n.healthSyncDescription),
value: syncState.isEnabled,
onChanged: syncState.isSyncing
? null
: (enabled) async {
final notifier = ref.read(healthSyncProvider.notifier);
if (enabled) {
final count = await notifier.enableSync();
// Imported entries land in the local Drift DB and surface through
// the measurement stream automatically, so no manual refresh is needed.
if (context.mounted && count > 0) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(i18n.healthSyncSuccess(count))),
);
}
} else {
await notifier.disableSync();
}
},
return Column(
children: [
ListTile(
title: Text(i18n.health, style: Theme.of(context).textTheme.headlineSmall),
),
SwitchListTile(
title: Text(i18n.healthSync),
subtitle: Text(i18n.healthSyncDescription),
value: syncState.isEnabled,
onChanged: syncState.isSyncing
? null
: (enabled) async {
final notifier = ref.read(healthSyncProvider.notifier);
if (enabled) {
final count = await notifier.enableSync();
// Imported entries land in the local Drift DB and surface through
// the measurement stream automatically, so no manual refresh is needed.
if (context.mounted && count > 0) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(i18n.healthSyncSuccess(count))),
);
}
} else {
await notifier.disableSync();
}
},
),
],
);
}
}

View File

@@ -56,7 +56,7 @@ final class HealthSyncNotifierProvider
}
}
String _$healthSyncNotifierHash() => r'9c7a678e7740bfa32db7638bd227d64da3bfef09';
String _$healthSyncNotifierHash() => r'bc23c2f6013f731414a7aa1ac98c618d1937c711';
/// Imports body metrics from Apple Health / Health Connect into measurement
/// categories. Read-only: reads the platform (via [HealthRepository]), writes to

View File

@@ -33,7 +33,7 @@ final class MeasurementNotifierProvider
MeasurementNotifier create() => MeasurementNotifier();
}
String _$measurementNotifierHash() => r'2072d9a5dd3b0c64830913541d236f5dfe28fbbc';
String _$measurementNotifierHash() => r'd21ed9e3cba86b2395e6df78d51fceb523e7c4fb';
abstract class _$MeasurementNotifier extends $StreamNotifier<List<MeasurementCategory>> {
Stream<List<MeasurementCategory>> build();

View File

@@ -2030,6 +2030,17 @@ class MockAppLocalizations extends _i1.Mock implements _i2.AppLocalizations {
)
as String);
@override
String get reorderCategories =>
(super.noSuchMethod(
Invocation.getter(#reorderCategories),
returnValue: _i3.dummyValue<String>(
this,
Invocation.getter(#reorderCategories),
),
)
as String);
@override
String get metricCustom =>
(super.noSuchMethod(