fix: Unlock app with leading 0 in pin is not possible

fixes https://github.com/krille-chan/fluffychat/issues/2388
This commit is contained in:
Christian Kußowski 2025-11-25 09:26:15 +01:00
parent 8d65b57a46
commit 07f2396790
No known key found for this signature in database
GPG key ID: E067ECD60F1A0652

View file

@ -21,6 +21,7 @@ class _LockScreenState extends State<LockScreen> {
final TextEditingController _textEditingController = TextEditingController(); final TextEditingController _textEditingController = TextEditingController();
void tryUnlock(String text) async { void tryUnlock(String text) async {
text = text.trim();
setState(() { setState(() {
_errorText = null; _errorText = null;
}); });
@ -35,7 +36,7 @@ class _LockScreenState extends State<LockScreen> {
return; return;
} }
if (AppLock.of(context).unlock(enteredPin.toString())) { if (AppLock.of(context).unlock(text)) {
setState(() { setState(() {
_inputBlocked = false; _inputBlocked = false;
_errorText = null; _errorText = null;
@ -60,57 +61,59 @@ class _LockScreenState extends State<LockScreen> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return ScaffoldMessenger(
appBar: AppBar( child: Scaffold(
title: Text(L10n.of(context).pleaseEnterYourPin), appBar: AppBar(
centerTitle: true, title: Text(L10n.of(context).pleaseEnterYourPin),
), centerTitle: true,
extendBodyBehindAppBar: true, ),
body: Center( extendBodyBehindAppBar: true,
child: Padding( body: Center(
padding: const EdgeInsets.all(16.0), child: Padding(
child: ConstrainedBox( padding: const EdgeInsets.all(16.0),
constraints: const BoxConstraints( child: ConstrainedBox(
maxWidth: FluffyThemes.columnWidth, constraints: const BoxConstraints(
), maxWidth: FluffyThemes.columnWidth,
child: ListView( ),
shrinkWrap: true, child: ListView(
children: [ shrinkWrap: true,
Center( children: [
child: Image.asset( Center(
'assets/info-logo.png', child: Image.asset(
width: 256, 'assets/info-logo.png',
), width: 256,
),
TextField(
controller: _textEditingController,
textInputAction: TextInputAction.done,
keyboardType: TextInputType.number,
obscureText: true,
autofocus: true,
textAlign: TextAlign.center,
readOnly: _inputBlocked,
onChanged: tryUnlock,
onSubmitted: tryUnlock,
style: const TextStyle(fontSize: 40),
inputFormatters: [
LengthLimitingTextInputFormatter(4),
],
decoration: InputDecoration(
errorText: _errorText,
hintText: '****',
suffix: IconButton(
icon: const Icon(Icons.lock_open_outlined),
onPressed: () => tryUnlock(_textEditingController.text),
), ),
), ),
), TextField(
if (_inputBlocked) controller: _textEditingController,
const Padding( textInputAction: TextInputAction.done,
padding: EdgeInsets.all(8.0), keyboardType: TextInputType.number,
child: LinearProgressIndicator(), obscureText: true,
autofocus: true,
textAlign: TextAlign.center,
readOnly: _inputBlocked,
onChanged: tryUnlock,
onSubmitted: tryUnlock,
style: const TextStyle(fontSize: 40),
inputFormatters: [
LengthLimitingTextInputFormatter(4),
],
decoration: InputDecoration(
errorText: _errorText,
hintText: '****',
suffix: IconButton(
icon: const Icon(Icons.lock_open_outlined),
onPressed: () => tryUnlock(_textEditingController.text),
),
),
), ),
], if (_inputBlocked)
const Padding(
padding: EdgeInsets.all(8.0),
child: LinearProgressIndicator(),
),
],
),
), ),
), ),
), ),