Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
digitalhoax committed Nov 2, 2022
2 parents fb53b8f + ca8e1b5 commit 1a13d73
Showing 1 changed file with 57 additions and 5 deletions.
62 changes: 57 additions & 5 deletions lib/passcode_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -124,9 +128,18 @@ class _PasscodeScreenState extends State<PasscodeScreen>
),
),
),
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(),
),
),
Expand Down Expand Up @@ -179,9 +192,18 @@ class _PasscodeScreenState extends State<PasscodeScreen>
),
),
),
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(),
),
)
Expand All @@ -200,7 +222,12 @@ class _PasscodeScreenState extends State<PasscodeScreen>
var list = <Widget>[];
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),
Expand All @@ -215,6 +242,12 @@ class _PasscodeScreenState extends State<PasscodeScreen>
return list;
}

_onConfirmButtonPressed() {
if (enteredPasscode.length > 0) {
widget.passwordEnteredCallback(enteredPasscode);
}
}

_onDeleteCancelButtonPressed() {
if (enteredPasscode.length > 0) {
setState(() {
Expand All @@ -234,9 +267,11 @@ class _PasscodeScreenState extends State<PasscodeScreen>
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);
}
}
Expand Down Expand Up @@ -291,4 +326,21 @@ class _PasscodeScreenState extends State<PasscodeScreen>
),
);
}

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',
),
),
),
);
}
}

0 comments on commit 1a13d73

Please sign in to comment.