This commit is contained in:
2026-03-20 20:50:26 +03:00
parent 50a34bf277
commit e2c6e38560
10 changed files with 213 additions and 3 deletions
+106
View File
@@ -4,6 +4,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'package:intl/intl.dart';
import '../../core/constants.dart';
import '../../core/services/biometric_service.dart';
import '../../shared/utils/currency_utils.dart';
import '../../shared/providers/amount_format_provider.dart';
import '../dashboard/provider.dart';
@@ -387,6 +388,8 @@ class _SettingsScreenState extends ConsumerState<SettingsScreen> {
),
const SizedBox(height: 16),
const _BiometricSection(),
Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
@@ -543,3 +546,106 @@ class _SettingsScreenState extends ConsumerState<SettingsScreen> {
);
}
}
class _BiometricSection extends StatefulWidget {
const _BiometricSection();
@override
State<_BiometricSection> createState() => _BiometricSectionState();
}
class _BiometricSectionState extends State<_BiometricSection> {
bool _available = false;
bool _enabled = false;
bool _loading = true;
@override
void initState() {
super.initState();
_load();
}
Future<void> _load() async {
final available = await BiometricService.isAvailable();
final enabled = await BiometricService.isEnabled();
if (mounted) {
setState(() {
_available = available;
_enabled = enabled;
_loading = false;
});
}
}
Future<void> _onToggle(bool val) async {
if (val) {
final ok = await BiometricService.authenticate();
if (!ok) return;
}
await BiometricService.setEnabled(val);
if (mounted) setState(() => _enabled = val);
}
@override
Widget build(BuildContext context) {
if (_loading || !_available) return const SizedBox.shrink();
final isDark = Theme.of(context).brightness == Brightness.dark;
return Column(
children: [
Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surface,
borderRadius: BorderRadius.circular(16),
border: isDark ? null : Border.all(color: const Color(0xFFDDDDEE), width: 1),
),
child: Row(
children: [
Container(
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(
color: AppColors.accent.withOpacity(0.15),
borderRadius: BorderRadius.circular(12),
),
child: const Icon(
Icons.fingerprint,
color: AppColors.accent,
size: 20,
),
),
const SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Biometric Lock',
style: Theme.of(context).textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.w600,
color: Theme.of(context).colorScheme.onSurface,
),
),
Text(
'Require fingerprint on app launch',
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.6),
),
),
],
),
),
Switch(
value: _enabled,
onChanged: _onToggle,
activeColor: const Color(0xFF7C6DED),
),
],
),
),
const SizedBox(height: 16),
],
);
}
}