From 7d4609eba0c2522300c40bb0645b6f49a38f27ae Mon Sep 17 00:00:00 2001 From: David Djordjevic Date: Wed, 2 Oct 2024 15:29:55 +0200 Subject: [PATCH] Fix pin not shown automatically after error --- packages/widget_toolkit_pin/CHANGELOG.md | 1 + .../widget_toolkit_pin/example/pubspec.lock | 2 +- .../blocs/pin_code_bloc.dart | 4 ++++ .../ui_components/pin_code_component.dart | 21 +++---------------- 4 files changed, 9 insertions(+), 19 deletions(-) diff --git a/packages/widget_toolkit_pin/CHANGELOG.md b/packages/widget_toolkit_pin/CHANGELOG.md index 3b63d471..2b37be2f 100644 --- a/packages/widget_toolkit_pin/CHANGELOG.md +++ b/packages/widget_toolkit_pin/CHANGELOG.md @@ -1,5 +1,6 @@ ## [0.2.1] * Fixed a visual bug where held buttons would remain stuck in the pressed state +* Fixed a visual bug where pin indicators wouldn't be displayed after an error is presented * Throw an error if biometrics aren't supported during biometrics authentication ## [0.2.0] diff --git a/packages/widget_toolkit_pin/example/pubspec.lock b/packages/widget_toolkit_pin/example/pubspec.lock index 3c4cf862..b634de33 100644 --- a/packages/widget_toolkit_pin/example/pubspec.lock +++ b/packages/widget_toolkit_pin/example/pubspec.lock @@ -939,7 +939,7 @@ packages: path: ".." relative: true source: path - version: "0.2.0" + version: "0.2.1" xdg_directories: dependency: transitive description: diff --git a/packages/widget_toolkit_pin/lib/src/lib_pin_code_with_biometrics/blocs/pin_code_bloc.dart b/packages/widget_toolkit_pin/lib/src/lib_pin_code_with_biometrics/blocs/pin_code_bloc.dart index 2f80704a..4252f7b1 100644 --- a/packages/widget_toolkit_pin/lib/src/lib_pin_code_with_biometrics/blocs/pin_code_bloc.dart +++ b/packages/widget_toolkit_pin/lib/src/lib_pin_code_with_biometrics/blocs/pin_code_bloc.dart @@ -77,6 +77,10 @@ class PinCodeBloc extends $PinCodeBloc { return Stream.value(_pinCode.value.length); }, ).asResultStream(), + errorState + .delay(const Duration(milliseconds: 300)) + .mapTo(0) + .asResultStream(), ]).whereSuccess().startWith(0).share(); @override diff --git a/packages/widget_toolkit_pin/lib/src/lib_pin_code_with_biometrics/ui_components/pin_code_component.dart b/packages/widget_toolkit_pin/lib/src/lib_pin_code_with_biometrics/ui_components/pin_code_component.dart index 1a16bd9b..8035e658 100644 --- a/packages/widget_toolkit_pin/lib/src/lib_pin_code_with_biometrics/ui_components/pin_code_component.dart +++ b/packages/widget_toolkit_pin/lib/src/lib_pin_code_with_biometrics/ui_components/pin_code_component.dart @@ -57,10 +57,6 @@ class PinCodeComponent extends StatefulWidget { /// to make it clickable. final PinCodeCustomKey? bottomRightKeyboardButton; - /// The duration of the input label animation presenting the error or input dots - final Duration inputLabelAnimationDuration = - const Duration(milliseconds: 300); - @override State createState() => _PinCodeComponentState(); } @@ -197,20 +193,13 @@ class _PinCodeComponentState extends State child: RxBlocBuilder( state: (bloc) => bloc.states.digitsCount, builder: (context, pinLength, bloc) => _buildPageContent( - pinLength: _pinLengthData(pinLength), + pinLength: pinLength.data ?? 0, context: context, ), ), ), ); - int _pinLengthData(AsyncSnapshot pinLength) { - if (pinLength.hasData && pinLength.data != null) { - return pinLength.data!; - } - return 0; - } - Widget _buildPageContent({ required int pinLength, required BuildContext context, @@ -244,7 +233,7 @@ class _PinCodeComponentState extends State child: child, ), child: AnimatedSwitcher( - duration: widget.inputLabelAnimationDuration, + duration: const Duration(milliseconds: 300), switchInCurve: Curves.easeOut, switchOutCurve: Curves.easeOut, transitionBuilder: (child, animation) { @@ -266,11 +255,7 @@ class _PinCodeComponentState extends State }, child: hasErrorText && widget.error != null ? _buildErrorText(context, widget.error!) - : RxBlocBuilder( - state: (bloc) => bloc.states.digitsCount, - builder: (context, pinLength, bloc) => - _buildMaskedKeysRow(context, pinLength.data ?? 0), - ), + : _buildMaskedKeysRow(context, pinLength), ), );