From 07f2396790897d0bf5ce3ed21ddba488602a5242 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Ku=C3=9Fowski?= Date: Tue, 25 Nov 2025 09:26:15 +0100 Subject: [PATCH] fix: Unlock app with leading 0 in pin is not possible fixes https://github.com/krille-chan/fluffychat/issues/2388 --- lib/widgets/lock_screen.dart | 101 ++++++++++++++++++----------------- 1 file changed, 52 insertions(+), 49 deletions(-) diff --git a/lib/widgets/lock_screen.dart b/lib/widgets/lock_screen.dart index 852455458..ab31e5edb 100644 --- a/lib/widgets/lock_screen.dart +++ b/lib/widgets/lock_screen.dart @@ -21,6 +21,7 @@ class _LockScreenState extends State { final TextEditingController _textEditingController = TextEditingController(); void tryUnlock(String text) async { + text = text.trim(); setState(() { _errorText = null; }); @@ -35,7 +36,7 @@ class _LockScreenState extends State { return; } - if (AppLock.of(context).unlock(enteredPin.toString())) { + if (AppLock.of(context).unlock(text)) { setState(() { _inputBlocked = false; _errorText = null; @@ -60,57 +61,59 @@ class _LockScreenState extends State { @override Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: Text(L10n.of(context).pleaseEnterYourPin), - centerTitle: true, - ), - extendBodyBehindAppBar: true, - body: Center( - child: Padding( - padding: const EdgeInsets.all(16.0), - child: ConstrainedBox( - constraints: const BoxConstraints( - maxWidth: FluffyThemes.columnWidth, - ), - child: ListView( - shrinkWrap: true, - children: [ - Center( - child: Image.asset( - '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), + return ScaffoldMessenger( + child: Scaffold( + appBar: AppBar( + title: Text(L10n.of(context).pleaseEnterYourPin), + centerTitle: true, + ), + extendBodyBehindAppBar: true, + body: Center( + child: Padding( + padding: const EdgeInsets.all(16.0), + child: ConstrainedBox( + constraints: const BoxConstraints( + maxWidth: FluffyThemes.columnWidth, + ), + child: ListView( + shrinkWrap: true, + children: [ + Center( + child: Image.asset( + 'assets/info-logo.png', + width: 256, ), ), - ), - if (_inputBlocked) - const Padding( - padding: EdgeInsets.all(8.0), - child: LinearProgressIndicator(), + 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), + ), + ), ), - ], + if (_inputBlocked) + const Padding( + padding: EdgeInsets.all(8.0), + child: LinearProgressIndicator(), + ), + ], + ), ), ), ),