Resolve all lints and deprecation warnings
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:health/health.dart';
|
||||
|
||||
import '../../providers/user_provider.dart';
|
||||
import '../../services/health_service.dart';
|
||||
|
||||
@@ -23,24 +23,30 @@ class _PrivacySettingsScreenState extends ConsumerState<PrivacySettingsScreen> {
|
||||
}
|
||||
|
||||
Future<void> _checkPermissions() async {
|
||||
final hasPermissions = await _healthService.hasPermissions(_healthService.menstruationDataTypes);
|
||||
final hasPermissions = await _healthService
|
||||
.hasPermissions(_healthService.menstruationDataTypes);
|
||||
setState(() {
|
||||
_hasPermissions = hasPermissions;
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _requestPermissions() async {
|
||||
final authorized = await _healthService.requestAuthorization(_healthService.menstruationDataTypes);
|
||||
final authorized = await _healthService
|
||||
.requestAuthorization(_healthService.menstruationDataTypes);
|
||||
if (authorized) {
|
||||
_hasPermissions = true;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Health app access granted!')),
|
||||
);
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Health app access granted!')),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
_hasPermissions = false;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Health app access denied.')),
|
||||
);
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Health app access denied.')),
|
||||
);
|
||||
}
|
||||
}
|
||||
setState(() {}); // Rebuild to update UI
|
||||
}
|
||||
@@ -48,14 +54,17 @@ class _PrivacySettingsScreenState extends ConsumerState<PrivacySettingsScreen> {
|
||||
Future<void> _syncPeriodDays(bool sync) async {
|
||||
if (sync) {
|
||||
if (!_hasPermissions) {
|
||||
// Request permissions if not already granted
|
||||
final authorized = await _healthService.requestAuthorization(_healthService.menstruationDataTypes);
|
||||
if (!authorized) {
|
||||
if (mounted) {
|
||||
final authorized = await _healthService
|
||||
.requestAuthorization(_healthService.menstruationDataTypes);
|
||||
if (mounted) {
|
||||
if (!authorized) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Cannot sync without health app permissions.')),
|
||||
const SnackBar(
|
||||
content: Text('Cannot sync without health app permissions.')),
|
||||
);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
_hasPermissions = true;
|
||||
@@ -70,7 +79,8 @@ class _PrivacySettingsScreenState extends ConsumerState<PrivacySettingsScreen> {
|
||||
final cycleEntries = ref.read(cycleEntriesProvider);
|
||||
|
||||
if (userProfile != null) {
|
||||
final success = await _healthService.writeMenstruationData(cycleEntries);
|
||||
final success =
|
||||
await _healthService.writeMenstruationData(cycleEntries);
|
||||
if (mounted) {
|
||||
if (success) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
@@ -90,7 +100,7 @@ class _PrivacySettingsScreenState extends ConsumerState<PrivacySettingsScreen> {
|
||||
);
|
||||
}
|
||||
}
|
||||
setState(() {}); // Rebuild to update UI
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
Future<void> _setPin() async {
|
||||
@@ -98,38 +108,40 @@ class _PrivacySettingsScreenState extends ConsumerState<PrivacySettingsScreen> {
|
||||
if (pin != null && pin.length >= 4) {
|
||||
final user = ref.read(userProfileProvider);
|
||||
if (user != null) {
|
||||
await ref.read(userProfileProvider.notifier).updateProfile(user.copyWith(privacyPin: pin));
|
||||
if (mounted) ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('PIN Set Successfully')));
|
||||
await ref
|
||||
.read(userProfileProvider.notifier)
|
||||
.updateProfile(user.copyWith(privacyPin: pin));
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('PIN Set Successfully')));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Future<void> _removePin() async {
|
||||
final user = ref.read(userProfileProvider);
|
||||
if (user == null) return;
|
||||
|
||||
// Require current PIN
|
||||
final currentPin = await _showPinDialog(context, title: 'Enter Current PIN');
|
||||
|
||||
final currentPin =
|
||||
await _showPinDialog(context, title: 'Enter Current PIN');
|
||||
if (currentPin == user.privacyPin) {
|
||||
await ref.read(userProfileProvider.notifier).updateProfile(
|
||||
// To clear fields, copyWith might need to handle nulls explicitly if written that way,
|
||||
// but here we might pass empty string or handle logic.
|
||||
// Actually, copyWith signature usually ignores nulls.
|
||||
// I'll assume updating with empty string or handle it in provider,
|
||||
// but for now let's just use empty string to signify removal if logic supports it.
|
||||
// Wait, copyWith `privacyPin: privacyPin ?? this.privacyPin`.
|
||||
// If I pass null, it keeps existing. I can't clear it via standard copyWith unless I change copyWith logic or pass emptiness.
|
||||
// I'll update the userProfile object directly and save? No, Hive object.
|
||||
// For now, let's treat "empty string" as no PIN if I can pass it.
|
||||
user.copyWith(privacyPin: '', isBioProtected: false, isHistoryProtected: false)
|
||||
);
|
||||
if (mounted) ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('PIN Removed')));
|
||||
await ref.read(userProfileProvider.notifier).updateProfile(user.copyWith(
|
||||
privacyPin: '', isBioProtected: false, isHistoryProtected: false));
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context)
|
||||
.showSnackBar(const SnackBar(content: Text('PIN Removed')));
|
||||
}
|
||||
} else {
|
||||
if (mounted) ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Incorrect PIN')));
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context)
|
||||
.showSnackBar(const SnackBar(content: Text('Incorrect PIN')));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<String?> _showPinDialog(BuildContext context, {required String title}) {
|
||||
Future<String?> _showPinDialog(BuildContext context,
|
||||
{required String title}) {
|
||||
final controller = TextEditingController();
|
||||
return showDialog<String>(
|
||||
context: context,
|
||||
@@ -143,7 +155,9 @@ class _PrivacySettingsScreenState extends ConsumerState<PrivacySettingsScreen> {
|
||||
decoration: const InputDecoration(hintText: 'Enter 4-digit PIN'),
|
||||
),
|
||||
actions: [
|
||||
TextButton(onPressed: () => Navigator.pop(context), child: const Text('Cancel')),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('Cancel')),
|
||||
ElevatedButton(
|
||||
onPressed: () => Navigator.pop(context, controller.text),
|
||||
child: const Text('OK'),
|
||||
@@ -155,9 +169,13 @@ class _PrivacySettingsScreenState extends ConsumerState<PrivacySettingsScreen> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
bool syncPeriodToHealth = _hasPermissions;
|
||||
final user = ref.watch(userProfileProvider);
|
||||
final hasPin = user?.privacyPin != null && user!.privacyPin!.isNotEmpty;
|
||||
if (user == null) {
|
||||
return const Scaffold(body: Center(child: CircularProgressIndicator()));
|
||||
}
|
||||
|
||||
final hasPin = user.privacyPin != null && user.privacyPin!.isNotEmpty;
|
||||
bool syncPeriodToHealth = _hasPermissions;
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
@@ -166,111 +184,135 @@ class _PrivacySettingsScreenState extends ConsumerState<PrivacySettingsScreen> {
|
||||
body: ListView(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
children: [
|
||||
// Security Section
|
||||
Text('App Security', style: Theme.of(context).textTheme.titleMedium?.copyWith(color: Theme.of(context).colorScheme.primary)),
|
||||
Text('App Security',
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.titleMedium
|
||||
?.copyWith(color: Theme.of(context).colorScheme.primary)),
|
||||
const SizedBox(height: 8),
|
||||
ListTile(
|
||||
title: const Text('Privacy PIN'),
|
||||
subtitle: Text(hasPin ? 'PIN is set' : 'Protect sensitive data with a PIN'),
|
||||
trailing: hasPin ? const Icon(Icons.lock, color: Colors.green) : const Icon(Icons.lock_open),
|
||||
subtitle: Text(
|
||||
hasPin ? 'PIN is set' : 'Protect sensitive data with a PIN'),
|
||||
trailing: hasPin
|
||||
? const Icon(Icons.lock, color: Colors.green)
|
||||
: const Icon(Icons.lock_open),
|
||||
onTap: () {
|
||||
if (hasPin) {
|
||||
showModalBottomSheet(context: context, builder: (context) => Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
ListTile(
|
||||
leading: const Icon(Icons.edit),
|
||||
title: const Text('Change PIN'),
|
||||
onTap: () {
|
||||
Navigator.pop(context);
|
||||
_setPin();
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.delete, color: Colors.red),
|
||||
title: const Text('Remove PIN'),
|
||||
onTap: () {
|
||||
Navigator.pop(context);
|
||||
_removePin();
|
||||
},
|
||||
),
|
||||
],
|
||||
));
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
builder: (context) => Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
ListTile(
|
||||
leading: const Icon(Icons.edit),
|
||||
title: const Text('Change PIN'),
|
||||
onTap: () {
|
||||
Navigator.pop(context);
|
||||
_setPin();
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading:
|
||||
const Icon(Icons.delete, color: Colors.red),
|
||||
title: const Text('Remove PIN'),
|
||||
onTap: () {
|
||||
Navigator.pop(context);
|
||||
_removePin();
|
||||
},
|
||||
),
|
||||
],
|
||||
));
|
||||
} else {
|
||||
_setPin();
|
||||
}
|
||||
},
|
||||
),
|
||||
|
||||
if (hasPin) ...[
|
||||
SwitchListTile(
|
||||
title: const Text('Use Biometrics'),
|
||||
subtitle: const Text('Unlock with FaceID / Fingerprint'),
|
||||
value: user?.isBioProtected ?? false,
|
||||
value: user.isBioProtected,
|
||||
onChanged: (val) {
|
||||
ref.read(userProfileProvider.notifier).updateProfile(user!.copyWith(isBioProtected: val));
|
||||
ref
|
||||
.read(userProfileProvider.notifier)
|
||||
.updateProfile(user.copyWith(isBioProtected: val));
|
||||
},
|
||||
),
|
||||
|
||||
const Divider(),
|
||||
const Text('Protected Features', style: TextStyle(fontWeight: FontWeight.bold, color: Colors.grey)),
|
||||
const Text('Protected Features',
|
||||
style:
|
||||
TextStyle(fontWeight: FontWeight.bold, color: Colors.grey)),
|
||||
SwitchListTile(
|
||||
title: const Text('Daily Logs'),
|
||||
value: user?.isLogProtected ?? false,
|
||||
value: user.isLogProtected,
|
||||
onChanged: (val) {
|
||||
ref.read(userProfileProvider.notifier).updateProfile(user!.copyWith(isLogProtected: val));
|
||||
ref
|
||||
.read(userProfileProvider.notifier)
|
||||
.updateProfile(user.copyWith(isLogProtected: val));
|
||||
},
|
||||
),
|
||||
SwitchListTile(
|
||||
SwitchListTile(
|
||||
title: const Text('Calendar'),
|
||||
value: user?.isCalendarProtected ?? false,
|
||||
value: user.isCalendarProtected,
|
||||
onChanged: (val) {
|
||||
ref.read(userProfileProvider.notifier).updateProfile(user!.copyWith(isCalendarProtected: val));
|
||||
ref
|
||||
.read(userProfileProvider.notifier)
|
||||
.updateProfile(user.copyWith(isCalendarProtected: val));
|
||||
},
|
||||
),
|
||||
SwitchListTile(
|
||||
SwitchListTile(
|
||||
title: const Text('Supplies / Pad Tracker'),
|
||||
value: user?.isSuppliesProtected ?? false,
|
||||
value: user.isSuppliesProtected,
|
||||
onChanged: (val) {
|
||||
ref.read(userProfileProvider.notifier).updateProfile(user!.copyWith(isSuppliesProtected: val));
|
||||
ref
|
||||
.read(userProfileProvider.notifier)
|
||||
.updateProfile(user.copyWith(isSuppliesProtected: val));
|
||||
},
|
||||
),
|
||||
SwitchListTile(
|
||||
title: const Text('Cycle History'),
|
||||
value: user?.isHistoryProtected ?? false,
|
||||
value: user.isHistoryProtected,
|
||||
onChanged: (val) {
|
||||
ref.read(userProfileProvider.notifier).updateProfile(user!.copyWith(isHistoryProtected: val));
|
||||
ref
|
||||
.read(userProfileProvider.notifier)
|
||||
.updateProfile(user.copyWith(isHistoryProtected: val));
|
||||
},
|
||||
),
|
||||
],
|
||||
|
||||
const Divider(height: 32),
|
||||
|
||||
// Health Section
|
||||
Text('Health App Integration', style: Theme.of(context).textTheme.titleMedium?.copyWith(color: Theme.of(context).colorScheme.primary)),
|
||||
Text('Health App Integration',
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.titleMedium
|
||||
?.copyWith(color: Theme.of(context).colorScheme.primary)),
|
||||
const SizedBox(height: 8),
|
||||
ListTile(
|
||||
title: const Text('Health Source'),
|
||||
subtitle: _hasPermissions
|
||||
? const Text('Connected to Health App.')
|
||||
: const Text('Not connected. Tap to grant access.'),
|
||||
trailing: _hasPermissions ? const Icon(Icons.check_circle, color: Colors.green) : const Icon(Icons.warning, color: Colors.orange),
|
||||
trailing: _hasPermissions
|
||||
? const Icon(Icons.check_circle, color: Colors.green)
|
||||
: const Icon(Icons.warning, color: Colors.orange),
|
||||
onTap: _requestPermissions,
|
||||
),
|
||||
SwitchListTile(
|
||||
title: const Text('Sync Period Days'),
|
||||
subtitle: const Text('Automatically sync period dates.'),
|
||||
value: syncPeriodToHealth,
|
||||
onChanged: _hasPermissions ? (value) async {
|
||||
if (value) {
|
||||
await _syncPeriodDays(true);
|
||||
} else {
|
||||
await _syncPeriodDays(false);
|
||||
}
|
||||
setState(() {
|
||||
syncPeriodToHealth = value; // Update local state for toggle
|
||||
});
|
||||
} : null,
|
||||
onChanged: _hasPermissions
|
||||
? (value) async {
|
||||
if (value) {
|
||||
await _syncPeriodDays(true);
|
||||
} else {
|
||||
await _syncPeriodDays(false);
|
||||
}
|
||||
setState(() {
|
||||
syncPeriodToHealth = value;
|
||||
});
|
||||
}
|
||||
: null,
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user