fix: pincode functionality

This commit is contained in:
2026-07-29 22:43:38 +02:00
parent 3cf4787e8c
commit a732e2d07f
8 changed files with 112 additions and 56 deletions
+40 -29
View File
@@ -1,3 +1,5 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:package_info_plus/package_info_plus.dart';
@@ -55,32 +57,37 @@ class _SettingsScreenViewState extends State<SettingsScreenView> {
});
}
Future<String?> _promptPin(String title, {String hint = 'Enter PIN'}) {
Future<String?> _promptPin(String title, {String hint = 'Enter PIN (4 digits)'}) {
final controller = TextEditingController();
return showDialog<String>(
context: context,
builder: (context) => AlertDialog(
title: Text(title),
content: TextField(
controller: controller,
autofocus: true,
obscureText: true,
keyboardType: TextInputType.number,
maxLength: 6,
decoration: InputDecoration(hintText: hint),
contentPadding: const EdgeInsets.fromLTRB(24, 20, 24, 0),
content: SizedBox(
width: 320,
child: TextField(
controller: controller,
autofocus: true,
obscureText: true,
keyboardType: TextInputType.number,
maxLength: 4,
decoration: InputDecoration(hintText: hint),
),
),
actionsPadding: const EdgeInsets.fromLTRB(16, 8, 16, 12),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('Cancel'),
),
const SizedBox(width: 12),
FilledButton(
onPressed: () => Navigator.pop(context, controller.text),
child: const Text('Confirm'),
),
],
actionsPadding: const EdgeInsets.symmetric(horizontal: 8),
),
);
}
@@ -93,11 +100,11 @@ class _SettingsScreenViewState extends State<SettingsScreenView> {
}
Future<void> _enablePin() async {
final pin = await _promptPin('Set PIN Code', hint: '46 digits');
final pin = await _promptPin('Set PIN Code', hint: '4 digits');
if (pin == null) return;
if (pin.length < 4) {
_showError('PIN must be at least 4 digits');
if (pin.length != 4) {
_showError('PIN must be exactly 4 digits');
return;
}
@@ -109,6 +116,7 @@ class _SettingsScreenViewState extends State<SettingsScreenView> {
return;
}
pinLockViewModel.setPinRequired(true);
await context.read<SettingsViewModel>().updatePinRequired(true);
}
@@ -116,11 +124,11 @@ class _SettingsScreenViewState extends State<SettingsScreenView> {
final current = await _promptPin('Enter Current PIN');
if (current == null) return;
final newPin = await _promptPin('Enter New PIN', hint: '46 digits');
final newPin = await _promptPin('Enter New PIN', hint: '4 digits');
if (newPin == null) return;
if (newPin.length < 4) {
_showError('PIN must be at least 4 digits');
if (newPin.length != 4) {
_showError('PIN must be exactly 4 digits');
return;
}
@@ -147,6 +155,7 @@ class _SettingsScreenViewState extends State<SettingsScreenView> {
return;
}
pinLockViewModel.setPinRequired(false);
await context.read<SettingsViewModel>().updatePinRequired(false);
}
@@ -252,20 +261,21 @@ class _SettingsScreenViewState extends State<SettingsScreenView> {
),
],
),
_SettingsSection(
title: 'Updates',
children: [
_SettingsTile(
icon: Icons.system_update_alt_rounded,
title: settingsViewModel.checkingForUpdates
? 'Checking for updates...'
: 'Check for updates',
onTap: settingsViewModel.checkingForUpdates
? null
: _checkForUpdates,
),
],
),
if (Platform.isAndroid)
_SettingsSection(
title: 'Updates',
children: [
_SettingsTile(
icon: Icons.system_update_alt_rounded,
title: settingsViewModel.checkingForUpdates
? 'Checking for updates...'
: 'Check for updates',
onTap: settingsViewModel.checkingForUpdates
? null
: _checkForUpdates,
),
],
),
const SizedBox(height: 40),
GestureDetector(
onTap: _onVersionTap,
@@ -289,6 +299,7 @@ class _SettingsScreenViewState extends State<SettingsScreenView> {
}
Future<void> _checkForUpdates() async {
if (!Platform.isAndroid) return;
final vm = context.read<SettingsViewModel>();
try {