Skip to content

Commit

Permalink
feat: Support pincode 4,5,6 digits #1892
Browse files Browse the repository at this point in the history
  • Loading branch information
bibash28 committed Sep 12, 2023
1 parent c0dc8dc commit 1753d3c
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 38 deletions.
74 changes: 44 additions & 30 deletions lib/dashboard/user_pin/view/user_pin_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import 'package:altme/app/app.dart';
import 'package:altme/dashboard/dashboard.dart';
import 'package:altme/l10n/l10n.dart';
import 'package:altme/pin_code/pin_code.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:secure_storage/secure_storage.dart';

class UserPinPage extends StatelessWidget {
const UserPinPage({
Expand Down Expand Up @@ -68,44 +68,58 @@ class _UserPinViewState extends State<UserPinView> {
super.dispose();
}

String? pinCodeValue;

@override
Widget build(BuildContext context) {
final l10n = context.l10n;
return WillPopScope(
onWillPop: () async => false,
child: BasePage(
backgroundColor: Theme.of(context).colorScheme.background,
scrollView: false,
body: PinCodeWidget(
title: l10n.pleaseInsertTheSecredCodeReceived,
passwordEnteredCallback: _onPasscodeEntered,
passwordDigits: 6,
deleteButton: Text(
l10n.delete,
style: Theme.of(context).textTheme.labelLarge,
),
cancelButton: Text(
l10n.cancel,
style: Theme.of(context).textTheme.labelLarge,
),
cancelCallback: _onPasscodeCancelled,
isValidCallback: () {
Navigator.pop(context);
widget.onProceed.call(pinCodeValue!);
},
shouldTriggerVerification: _verificationNotifier.stream,
),
child: BlocBuilder<PinCodeViewCubit, PinCodeViewState>(
builder: (context, state) {
return BasePage(
backgroundColor: Theme.of(context).colorScheme.background,
scrollView: false,
body: PinCodeWidget(
title: l10n.pleaseInsertTheSecredCodeReceived,
passwordEnteredCallback: (String enterPasscode) {
_verificationNotifier.add(true);
},
passwordDigits: 6,
deleteButton: Text(
l10n.delete,
style: Theme.of(context).textTheme.labelLarge,
),
cancelButton: Text(
l10n.cancel,
style: Theme.of(context).textTheme.labelLarge,
),
cancelCallback: _onPasscodeCancelled,
isValidCallback: () {
Navigator.pop(context);
widget.onProceed.call(state.enteredPasscode);
},
doneButton: state.enteredPasscode.length < 4
? null
: CupertinoButton(
onPressed: () {
Navigator.pop(context);
widget.onProceed.call(state.enteredPasscode);
},
child: Container(
margin: const EdgeInsets.all(24),
child: Text(
l10n.proceed,
style: Theme.of(context).textTheme.labelLarge,
),
),
),
shouldTriggerVerification: _verificationNotifier.stream,
),
);
},
),
);
}

Future<void> _onPasscodeEntered(String enteredPasscode) async {
pinCodeValue = enteredPasscode;
_verificationNotifier.add(true);
}

void _onPasscodeCancelled() {
Navigator.of(context).pop();
widget.onCancel.call();
Expand Down
21 changes: 13 additions & 8 deletions lib/pin_code/widgets/pin_code_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class PinCodeWidget extends StatefulWidget {
KeyboardUIConfig? keyboardUIConfig,
this.bottomWidget,
this.backgroundColor,
this.doneButton,
this.cancelCallback,
this.subTitle,
this.header,
Expand All @@ -29,6 +30,7 @@ class PinCodeWidget extends StatefulWidget {
keyboardUIConfig = keyboardUIConfig ?? const KeyboardUIConfig();

final Widget? header;
final Widget? doneButton;
final String title;
final String? subTitle;
final int passwordDigits;
Expand Down Expand Up @@ -154,16 +156,19 @@ class _PinCodeWidgetState extends State<PinCodeWidget>
Positioned(
bottom: 0,
right: 0,
child: Align(
alignment: Alignment.bottomRight,
child: DeleteButton(
cancelButton: widget.cancelButton,
deleteButton: widget.deleteButton,
cancelCallback: widget.cancelCallback,
keyboardUIConfig: widget.keyboardUIConfig,
),
child: DeleteButton(
cancelButton: widget.cancelButton,
deleteButton: widget.deleteButton,
cancelCallback: widget.cancelCallback,
keyboardUIConfig: widget.keyboardUIConfig,
),
),
if (widget.doneButton != null)
Positioned(
bottom: 0,
left: 0,
child: widget.doneButton!,
),
],
),
],
Expand Down

0 comments on commit 1753d3c

Please sign in to comment.