From a8159f9525e30f1362e306749ce62d9a611f82bb Mon Sep 17 00:00:00 2001 From: Thibault Deckers Date: Mon, 20 Feb 2023 18:11:32 +0100 Subject: [PATCH] #532 use google-free dependency for pin input --- lib/utils/dependencies.dart | 4 +- .../filter_editors/password_dialog.dart | 13 +++++- .../dialogs/filter_editors/pin_dialog.dart | 46 +++++++++++++------ pubspec.lock | 24 ++-------- pubspec.yaml | 2 +- 5 files changed, 51 insertions(+), 38 deletions(-) diff --git a/lib/utils/dependencies.dart b/lib/utils/dependencies.dart index 4076d7df9..9219ac084 100644 --- a/lib/utils/dependencies.dart +++ b/lib/utils/dependencies.dart @@ -266,9 +266,9 @@ class Dependencies { sourceUrl: 'https://github.com/diegoveloper/flutter_percent_indicator', ), Dependency( - name: 'Pinput', + name: 'Pin Code Fields', license: mit, - sourceUrl: 'https://github.com/Tkko/Flutter_PinPut', + sourceUrl: 'https://github.com/adar2378/pin_code_fields', ), Dependency( name: 'Provider', diff --git a/lib/widgets/dialogs/filter_editors/password_dialog.dart b/lib/widgets/dialogs/filter_editors/password_dialog.dart index 1bce02e90..80b075e6b 100644 --- a/lib/widgets/dialogs/filter_editors/password_dialog.dart +++ b/lib/widgets/dialogs/filter_editors/password_dialog.dart @@ -44,7 +44,18 @@ class _PasswordDialogState extends State { onSubmitted: (password) { if (widget.needConfirmation) { if (_confirming) { - Navigator.maybeOf(context)?.pop(_firstPassword == password ? password : null); + final match = _firstPassword == password; + Navigator.maybeOf(context)?.pop(match ? password : null); + if (!match) { + showDialog( + context: context, + builder: (context) => AvesDialog( + content: Text(context.l10n.genericFailureFeedback), + actions: const [OkButton()], + ), + routeSettings: const RouteSettings(name: AvesDialog.warningRouteName), + ); + } } else { _firstPassword = password; _controller.clear(); diff --git a/lib/widgets/dialogs/filter_editors/pin_dialog.dart b/lib/widgets/dialogs/filter_editors/pin_dialog.dart index 6afd18420..7394061c0 100644 --- a/lib/widgets/dialogs/filter_editors/pin_dialog.dart +++ b/lib/widgets/dialogs/filter_editors/pin_dialog.dart @@ -1,7 +1,7 @@ import 'package:aves/widgets/common/extensions/build_context.dart'; import 'package:aves/widgets/dialogs/aves_dialog.dart'; import 'package:flutter/material.dart'; -import 'package:pinput/pinput.dart'; +import 'package:pin_code_fields/pin_code_fields.dart'; class PinDialog extends StatefulWidget { static const routeName = '/dialog/pin'; @@ -19,18 +19,12 @@ class PinDialog extends StatefulWidget { class _PinDialogState extends State { final _controller = TextEditingController(); - final _focusNode = FocusNode(); bool _confirming = false; String? _firstPin; - @override - void initState() { - super.initState(); - _focusNode.requestFocus(); - } - @override Widget build(BuildContext context) { + final colorScheme = Theme.of(context).colorScheme; return AvesDialog( content: Column( mainAxisSize: MainAxisSize.min, @@ -38,24 +32,48 @@ class _PinDialogState extends State { Text(_confirming ? context.l10n.pinDialogConfirm : context.l10n.pinDialogEnter), Padding( padding: const EdgeInsets.symmetric(vertical: 16), - child: Pinput( + child: PinCodeTextField( + appContext: context, + length: 4, + controller: _controller, + obscureText: true, + onChanged: (v) {}, onCompleted: (pin) { if (widget.needConfirmation) { if (_confirming) { - Navigator.maybeOf(context)?.pop(_firstPin == pin ? pin : null); + final match = _firstPin == pin; + Navigator.maybeOf(context)?.pop(match ? pin : null); + if (!match) { + showDialog( + context: context, + builder: (context) => AvesDialog( + content: Text(context.l10n.genericFailureFeedback), + actions: const [OkButton()], + ), + routeSettings: const RouteSettings(name: AvesDialog.warningRouteName), + ); + } } else { _firstPin = pin; _controller.clear(); setState(() => _confirming = true); - WidgetsBinding.instance.addPostFrameCallback((_) => _focusNode.requestFocus()); } } else { Navigator.maybeOf(context)?.pop(pin); } }, - controller: _controller, - focusNode: _focusNode, - obscureText: true, + animationType: AnimationType.scale, + keyboardType: TextInputType.number, + autoFocus: true, + autoDismissKeyboard: !widget.needConfirmation || _confirming, + pinTheme: PinTheme( + activeColor: colorScheme.onBackground, + inactiveColor: colorScheme.onBackground, + selectedColor: colorScheme.secondary, + selectedFillColor: colorScheme.secondary, + borderRadius: BorderRadius.circular(8), + shape: PinCodeFieldShape.box, + ), ), ), ], diff --git a/pubspec.lock b/pubspec.lock index 6c8596cb0..fd44d6786 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -917,14 +917,14 @@ packages: url: "https://pub.dev" source: hosted version: "5.1.0" - pinput: + pin_code_fields: dependency: "direct main" description: - name: pinput - sha256: e6aabd1571dde622f9b942f62ac2c80f84b0b50f95fa209a93e78f7d621e1f82 + name: pin_code_fields + sha256: c8652519d14688f3fe2a8288d86910a46aa0b9046d728f292d3bf6067c31b4c7 url: "https://pub.dev" source: hosted - version: "2.2.23" + version: "7.4.0" platform: dependency: transitive description: @@ -1162,14 +1162,6 @@ packages: description: flutter source: sdk version: "0.0.99" - smart_auth: - dependency: transitive - description: - name: smart_auth - sha256: "8cfaec55b77d5930ed1666bb7ae70db5bade099bb1422401386853b400962113" - url: "https://pub.dev" - source: hosted - version: "1.0.8" smooth_page_indicator: dependency: "direct main" description: @@ -1339,14 +1331,6 @@ packages: url: "https://pub.dev" source: hosted version: "0.3.1" - universal_platform: - dependency: transitive - description: - name: universal_platform - sha256: d315be0f6641898b280ffa34e2ddb14f3d12b1a37882557869646e0cc363d0cc - url: "https://pub.dev" - source: hosted - version: "1.0.0+1" url_launcher: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 270faa71b..3b4c64ead 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -83,7 +83,7 @@ dependencies: pdf: percent_indicator: permission_handler: - pinput: + pin_code_fields: printing: proj4dart: provider: