mirror of
https://github.com/wger-project/flutter.git
synced 2026-11-28 17:08:29 +01:00
Fix source default, hide health settings section when unavailable
This commit is contained in:
@@ -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',
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user