From ca8e1b5d84cd043758478a252ca24fee72d93440 Mon Sep 17 00:00:00 2001 From: Simon-Lennert Raesch Date: Wed, 23 Mar 2022 15:09:22 +0100 Subject: [PATCH 1/2] added option for variable pin length --- lib/passcode_screen.dart | 62 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 57 insertions(+), 5 deletions(-) diff --git a/lib/passcode_screen.dart b/lib/passcode_screen.dart index 41f51a9..072a19a 100644 --- a/lib/passcode_screen.dart +++ b/lib/passcode_screen.dart @@ -15,6 +15,8 @@ typedef CancelCallback = void Function(); class PasscodeScreen extends StatefulWidget { final Widget title; final int passwordDigits; + final bool variablePinLength; + final Widget? confirmButton; final PasswordEnteredCallback passwordEnteredCallback; // Cancel button and delete button will be switched based on the screen state final Widget cancelButton; @@ -35,6 +37,8 @@ class PasscodeScreen extends StatefulWidget { Key? key, required this.title, this.passwordDigits = 6, + this.variablePinLength = false, + this.confirmButton, required this.passwordEnteredCallback, required this.cancelButton, required this.deleteButton, @@ -124,9 +128,18 @@ class _PasscodeScreenState extends State ), ), ), + if (widget.variablePinLength) + Positioned( + child: Align( + alignment: Alignment.bottomRight, + child: _buildConfirmButton(), + ), + ), Positioned( child: Align( - alignment: Alignment.bottomRight, + alignment: (widget.variablePinLength) + ? Alignment.bottomLeft + : Alignment.bottomRight, child: _buildDeleteButton(), ), ), @@ -179,9 +192,18 @@ class _PasscodeScreenState extends State ), ), ), + if (widget.variablePinLength) + Positioned( + child: Align( + alignment: Alignment.bottomRight, + child: _buildConfirmButton(), + ), + ), Positioned( child: Align( - alignment: Alignment.bottomRight, + alignment: (widget.variablePinLength) + ? Alignment.bottomLeft + : Alignment.bottomRight, child: _buildDeleteButton(), ), ) @@ -200,7 +222,12 @@ class _PasscodeScreenState extends State var list = []; var config = widget.circleUIConfig; var extraSize = animation.value; - for (int i = 0; i < widget.passwordDigits; i++) { + for (int i = 0; + i < + ((widget.variablePinLength) + ? enteredPasscode.length + : widget.passwordDigits); + i++) { list.add( Container( margin: EdgeInsets.all(8), @@ -215,6 +242,12 @@ class _PasscodeScreenState extends State return list; } + _onConfirmButtonPressed() { + if (enteredPasscode.length > 0) { + widget.passwordEnteredCallback(enteredPasscode); + } + } + _onDeleteCancelButtonPressed() { if (enteredPasscode.length > 0) { setState(() { @@ -234,9 +267,11 @@ class _PasscodeScreenState extends State return; } setState(() { - if (enteredPasscode.length < widget.passwordDigits) { + if (widget.variablePinLength || + enteredPasscode.length < widget.passwordDigits) { enteredPasscode += text; - if (enteredPasscode.length == widget.passwordDigits) { + if (!widget.variablePinLength && + enteredPasscode.length == widget.passwordDigits) { widget.passwordEnteredCallback(enteredPasscode); } } @@ -291,4 +326,21 @@ class _PasscodeScreenState extends State ), ); } + + Widget _buildConfirmButton() { + return Container( + child: CupertinoButton( + onPressed: _onConfirmButtonPressed, + child: Container( + margin: widget.keyboardUIConfig.digitInnerMargin, + child: widget.confirmButton ?? + Text( + 'OK', + style: const TextStyle(fontSize: 16, color: Colors.white), + semanticsLabel: 'OK', + ), + ), + ), + ); + } } From 362ffad77fc4983d63b25b756b54fac829935085 Mon Sep 17 00:00:00 2001 From: Simon-Lennert Raesch Date: Wed, 2 Nov 2022 13:07:04 +0100 Subject: [PATCH 2/2] limit chars to 10 on variable pin length --- lib/passcode_screen.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/passcode_screen.dart b/lib/passcode_screen.dart index 072a19a..270a23a 100644 --- a/lib/passcode_screen.dart +++ b/lib/passcode_screen.dart @@ -267,7 +267,7 @@ class _PasscodeScreenState extends State return; } setState(() { - if (widget.variablePinLength || + if ((widget.variablePinLength && enteredPasscode.length < 10) || enteredPasscode.length < widget.passwordDigits) { enteredPasscode += text; if (!widget.variablePinLength &&