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 d8b80232..c6d9f11e 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 @@ -164,7 +164,7 @@ class PinCodeBloc extends $PinCodeBloc { /// Authenticates the user with biometrics after which the pin code is /// retrieved from the device and checked. - Future _authenticateWithBiometrics() async { + Future _authenticateWithBiometrics() async { if (!await biometricAuthenticationService.isDeviceSupported) { throw ErrorEnableBiometrics(BiometricsMessage.notSupported); } diff --git a/packages/widget_toolkit_pin/lib/src/lib_pin_code_with_biometrics/di/pin_code_dependencies.dart b/packages/widget_toolkit_pin/lib/src/lib_pin_code_with_biometrics/di/pin_code_dependencies.dart index de0436e8..e6611b58 100644 --- a/packages/widget_toolkit_pin/lib/src/lib_pin_code_with_biometrics/di/pin_code_dependencies.dart +++ b/packages/widget_toolkit_pin/lib/src/lib_pin_code_with_biometrics/di/pin_code_dependencies.dart @@ -5,7 +5,6 @@ import 'package:widget_toolkit_biometrics/widget_toolkit_biometrics.dart'; import '../../../widget_toolkit_pin.dart'; import '../data_source/biometrics_disabled_local_data_source.dart'; -import '../data_source/pin_biometrics_auth_data_source.dart'; import '../repositories/pin_biometrics_repository.dart'; import '../services/pin_biometrics_service.dart'; @@ -14,22 +13,26 @@ class PinCodeDependencies { this.pinCodeService, this.biometricsLocalDataSource, this.localizedReason, + this.biometricsAuthDataSource, ); factory PinCodeDependencies.from({ required PinCodeService pinCodeService, required BiometricsLocalDataSource? biometricsLocalDataSource, required String localizedReason, + PinBiometricsAuthDataSource? biometricsAuthDataSource, }) => PinCodeDependencies._( pinCodeService, biometricsLocalDataSource, localizedReason, + biometricsAuthDataSource, ); final String localizedReason; final PinCodeService pinCodeService; final BiometricsLocalDataSource? biometricsLocalDataSource; + final PinBiometricsAuthDataSource? biometricsAuthDataSource; late List providers = [ ..._localAuthentication, @@ -47,9 +50,11 @@ class PinCodeDependencies { late final List _dataSources = [ Provider( - create: (context) => PinBiometricsAuthDataSource( - localAuthentication: context.read(), - ), + create: (context) => + biometricsAuthDataSource ?? + PinBiometricsAuthDataSource( + localAuthentication: context.read(), + ), ), if (biometricsLocalDataSource == null) Provider( diff --git a/packages/widget_toolkit_pin/lib/src/lib_pin_code_with_biometrics/ui_components/pin_code_keyboard.dart b/packages/widget_toolkit_pin/lib/src/lib_pin_code_with_biometrics/ui_components/pin_code_keyboard.dart index af4c2c3f..7c93924c 100644 --- a/packages/widget_toolkit_pin/lib/src/lib_pin_code_with_biometrics/ui_components/pin_code_keyboard.dart +++ b/packages/widget_toolkit_pin/lib/src/lib_pin_code_with_biometrics/ui_components/pin_code_keyboard.dart @@ -47,6 +47,7 @@ class PinCodeKeyboard extends StatelessWidget { required this.pinCodeService, required this.translateError, this.biometricsLocalDataSource, + this.biometricsAuthDataSource, this.mapBiometricMessageToString, this.onAuthenticated, this.deleteKeyButton, @@ -72,6 +73,11 @@ class PinCodeKeyboard extends StatelessWidget { /// for the package final BiometricsLocalDataSource? biometricsLocalDataSource; + /// Provides a contract for custom biometrics authentication plugin. If this + /// parameter is not provided, a default one will be used featuring + /// [LocalAuthentication] from the local_auth package + final PinBiometricsAuthDataSource? biometricsAuthDataSource; + /// Callback called when the user authentication succeeds. It accepts a dynamic /// value which is forwarded from the `verifyPinCode` method of the [pinCodeService]. final Function(dynamic)? onAuthenticated; @@ -129,6 +135,7 @@ class PinCodeKeyboard extends StatelessWidget { ...PinCodeDependencies.from( pinCodeService: pinCodeService, biometricsLocalDataSource: biometricsLocalDataSource, + biometricsAuthDataSource: biometricsAuthDataSource, localizedReason: localizedReason ?? _enterPinWithBiometrics, ).providers, ], diff --git a/packages/widget_toolkit_pin/lib/widget_toolkit_pin.dart b/packages/widget_toolkit_pin/lib/widget_toolkit_pin.dart index cac77bcb..18db0f3d 100644 --- a/packages/widget_toolkit_pin/lib/widget_toolkit_pin.dart +++ b/packages/widget_toolkit_pin/lib/widget_toolkit_pin.dart @@ -2,6 +2,7 @@ library widget_toolkit_pin; export 'src/base/utils/theme/pin_code_theme.dart'; export 'src/lib_pin_code_with_biometrics/blocs/pin_code_bloc.dart'; +export 'src/lib_pin_code_with_biometrics/data_source/pin_biometrics_auth_data_source.dart'; export 'src/lib_pin_code_with_biometrics/services/pin_code_service.dart'; export 'src/lib_pin_code_with_biometrics/ui_components/pin_code_custom_key.dart'; export 'src/lib_pin_code_with_biometrics/ui_components/pin_code_keyboard.dart';