feat: reformat some pages

This commit is contained in:
2026-10-26 23:15:05 +01:00
parent 65e5e286b0
commit 08f4847800
17 changed files with 812 additions and 198 deletions
+56 -111
View File
@@ -8,13 +8,14 @@ import 'package:provider/provider.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
import '../l10n/app_localizations.dart';
import '../l10n/app_localizations_helpers.dart';
import '../models/app_error.dart';
import '../models/settings.dart';
import '../utils/app_update_util.dart';
import '../utils/navigation.dart';
import '../viewmodels/admin_pin_view_model.dart';
import '../viewmodels/pin_lock_view_model.dart';
import '../viewmodels/settings_view_model.dart';
import 'pin_lock_view.dart';
class SettingsScreenView extends StatefulWidget {
const SettingsScreenView({super.key});
@@ -80,40 +81,34 @@ class _SettingsScreenViewState extends State<SettingsScreenView> {
});
}
Future<String?> _promptPin(String title, {String? hint}) {
final controller = TextEditingController();
final l10n = AppLocalizations.of(context);
return showDialog<String>(
context: context,
builder: (context) => AlertDialog(
title: Text(title),
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),
),
/// Shows the PIN keypad full screen; true once the PIN step succeeded.
Future<bool> _showPinEntry({
required PinEntryMode mode,
bool isAdmin = false,
String? title,
Future<bool> Function(String)? onVerify,
Future<bool> Function(String)? onSet,
Future<bool> Function(String, String)? onChange,
AppError? Function()? error,
}) async {
final succeeded = await Navigator.of(context).push<bool>(
MaterialPageRoute(
fullscreenDialog: true,
builder: (routeContext) => PinEntryView(
mode: mode,
isAdmin: isAdmin,
title: title,
onVerify: onVerify,
onSet: onSet,
onChange: onChange,
error: error,
onSuccess: () => Navigator.pop(routeContext, true),
onClose: () => Navigator.pop(routeContext, false),
),
actionsPadding: const EdgeInsets.fromLTRB(16, 8, 16, 12),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: Text(l10n.cancel),
),
const SizedBox(width: 12),
FilledButton(
onPressed: () => Navigator.pop(context, controller.text),
child: Text(l10n.confirm),
),
],
),
);
return succeeded ?? false;
}
Future<T?> _pickOption<T>(
@@ -140,7 +135,7 @@ class _SettingsScreenViewState extends State<SettingsScreenView> {
);
}
void _showError(String message) {
void _showMessage(String message) {
if (!mounted) return;
ScaffoldMessenger.of(
context,
@@ -151,46 +146,19 @@ class _SettingsScreenViewState extends State<SettingsScreenView> {
final l10n = AppLocalizations.of(context);
final pinLockViewModel = context.read<PinLockViewModel>();
final settingsViewModel = context.read<SettingsViewModel>();
final pin = await _promptPin(l10n.setPinCode, hint: l10n.fourDigits);
if (pin == null) return;
if (pin.length != 4) {
_showError(l10n.pinExactlyFour);
return;
}
final success = await pinLockViewModel.setPin(pin);
if (!success) {
_showError(l10n.errorText(pinLockViewModel.error));
return;
}
if (!await _showPinEntry(mode: PinEntryMode.create)) return;
pinLockViewModel.setPinRequired(true);
await settingsViewModel.updatePinRequired(true);
_showMessage(l10n.pinSaved);
}
Future<void> _changePin() async {
final l10n = AppLocalizations.of(context);
final pinLockViewModel = context.read<PinLockViewModel>();
final current = await _promptPin(l10n.enterCurrentPin);
if (current == null) return;
final newPin = await _promptPin(l10n.enterNewPin, hint: l10n.fourDigits);
if (newPin == null) return;
if (newPin.length != 4) {
_showError(l10n.pinExactlyFour);
return;
}
final success = await pinLockViewModel.changePin(
currentPin: current,
newPin: newPin,
);
if (!success) {
_showError(l10n.errorText(pinLockViewModel.error));
if (await _showPinEntry(mode: PinEntryMode.change)) {
_showMessage(l10n.pinSaved);
}
}
@@ -198,15 +166,13 @@ class _SettingsScreenViewState extends State<SettingsScreenView> {
final l10n = AppLocalizations.of(context);
final pinLockViewModel = context.read<PinLockViewModel>();
final settingsViewModel = context.read<SettingsViewModel>();
final current = await _promptPin(l10n.enterCurrentPin);
if (current == null) return;
final success = await pinLockViewModel.disablePin(current);
if (!success) {
_showError(l10n.errorText(pinLockViewModel.error));
return;
}
final disabled = await _showPinEntry(
mode: PinEntryMode.unlock,
title: l10n.enterCurrentPin,
onVerify: pinLockViewModel.disablePin,
);
if (!disabled) return;
pinLockViewModel.setPinRequired(false);
await settingsViewModel.updatePinRequired(false);
@@ -216,46 +182,25 @@ class _SettingsScreenViewState extends State<SettingsScreenView> {
final l10n = AppLocalizations.of(context);
final adminPinViewModel = context.read<AdminPinViewModel>();
if (!adminPinViewModel.isPinSet) {
final pin = await _promptPin(l10n.setAdminPin, hint: l10n.fourDigits);
if (pin == null) return;
final saved = adminPinViewModel.isPinSet
? await _showPinEntry(
mode: PinEntryMode.change,
isAdmin: true,
onVerify: adminPinViewModel.verify,
onChange: (currentPin, newPin) => adminPinViewModel.changePin(
currentPin: currentPin,
newPin: newPin,
),
error: () => adminPinViewModel.error,
)
: await _showPinEntry(
mode: PinEntryMode.create,
isAdmin: true,
onSet: adminPinViewModel.setPin,
error: () => adminPinViewModel.error,
);
if (pin.length != 4) {
_showError(l10n.pinExactlyFour);
return;
}
final success = await adminPinViewModel.setPin(pin);
if (!success) {
_showError(l10n.errorText(adminPinViewModel.error));
return;
}
return;
}
final current = await _promptPin(l10n.enterCurrentAdminPin);
if (current == null) return;
final newPin = await _promptPin(
l10n.enterNewAdminPin,
hint: l10n.fourDigits,
);
if (newPin == null) return;
if (newPin.length != 4) {
_showError(l10n.pinExactlyFour);
return;
}
final success = await adminPinViewModel.changePin(
currentPin: current,
newPin: newPin,
);
if (!success) {
_showError(l10n.errorText(adminPinViewModel.error));
}
if (saved) _showMessage(l10n.pinSaved);
}
@override