#532 use google-free dependency for pin input
This commit is contained in:
parent
f0bf70e3b1
commit
a8159f9525
5 changed files with 51 additions and 38 deletions
|
@ -266,9 +266,9 @@ class Dependencies {
|
||||||
sourceUrl: 'https://github.com/diegoveloper/flutter_percent_indicator',
|
sourceUrl: 'https://github.com/diegoveloper/flutter_percent_indicator',
|
||||||
),
|
),
|
||||||
Dependency(
|
Dependency(
|
||||||
name: 'Pinput',
|
name: 'Pin Code Fields',
|
||||||
license: mit,
|
license: mit,
|
||||||
sourceUrl: 'https://github.com/Tkko/Flutter_PinPut',
|
sourceUrl: 'https://github.com/adar2378/pin_code_fields',
|
||||||
),
|
),
|
||||||
Dependency(
|
Dependency(
|
||||||
name: 'Provider',
|
name: 'Provider',
|
||||||
|
|
|
@ -44,7 +44,18 @@ class _PasswordDialogState extends State<PasswordDialog> {
|
||||||
onSubmitted: (password) {
|
onSubmitted: (password) {
|
||||||
if (widget.needConfirmation) {
|
if (widget.needConfirmation) {
|
||||||
if (_confirming) {
|
if (_confirming) {
|
||||||
Navigator.maybeOf(context)?.pop<String>(_firstPassword == password ? password : null);
|
final match = _firstPassword == password;
|
||||||
|
Navigator.maybeOf(context)?.pop<String>(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 {
|
} else {
|
||||||
_firstPassword = password;
|
_firstPassword = password;
|
||||||
_controller.clear();
|
_controller.clear();
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import 'package:aves/widgets/common/extensions/build_context.dart';
|
import 'package:aves/widgets/common/extensions/build_context.dart';
|
||||||
import 'package:aves/widgets/dialogs/aves_dialog.dart';
|
import 'package:aves/widgets/dialogs/aves_dialog.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:pinput/pinput.dart';
|
import 'package:pin_code_fields/pin_code_fields.dart';
|
||||||
|
|
||||||
class PinDialog extends StatefulWidget {
|
class PinDialog extends StatefulWidget {
|
||||||
static const routeName = '/dialog/pin';
|
static const routeName = '/dialog/pin';
|
||||||
|
@ -19,18 +19,12 @@ class PinDialog extends StatefulWidget {
|
||||||
|
|
||||||
class _PinDialogState extends State<PinDialog> {
|
class _PinDialogState extends State<PinDialog> {
|
||||||
final _controller = TextEditingController();
|
final _controller = TextEditingController();
|
||||||
final _focusNode = FocusNode();
|
|
||||||
bool _confirming = false;
|
bool _confirming = false;
|
||||||
String? _firstPin;
|
String? _firstPin;
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
_focusNode.requestFocus();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final colorScheme = Theme.of(context).colorScheme;
|
||||||
return AvesDialog(
|
return AvesDialog(
|
||||||
content: Column(
|
content: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
@ -38,24 +32,48 @@ class _PinDialogState extends State<PinDialog> {
|
||||||
Text(_confirming ? context.l10n.pinDialogConfirm : context.l10n.pinDialogEnter),
|
Text(_confirming ? context.l10n.pinDialogConfirm : context.l10n.pinDialogEnter),
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||||
child: Pinput(
|
child: PinCodeTextField(
|
||||||
|
appContext: context,
|
||||||
|
length: 4,
|
||||||
|
controller: _controller,
|
||||||
|
obscureText: true,
|
||||||
|
onChanged: (v) {},
|
||||||
onCompleted: (pin) {
|
onCompleted: (pin) {
|
||||||
if (widget.needConfirmation) {
|
if (widget.needConfirmation) {
|
||||||
if (_confirming) {
|
if (_confirming) {
|
||||||
Navigator.maybeOf(context)?.pop<String>(_firstPin == pin ? pin : null);
|
final match = _firstPin == pin;
|
||||||
|
Navigator.maybeOf(context)?.pop<String>(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 {
|
} else {
|
||||||
_firstPin = pin;
|
_firstPin = pin;
|
||||||
_controller.clear();
|
_controller.clear();
|
||||||
setState(() => _confirming = true);
|
setState(() => _confirming = true);
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) => _focusNode.requestFocus());
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Navigator.maybeOf(context)?.pop<String>(pin);
|
Navigator.maybeOf(context)?.pop<String>(pin);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
controller: _controller,
|
animationType: AnimationType.scale,
|
||||||
focusNode: _focusNode,
|
keyboardType: TextInputType.number,
|
||||||
obscureText: true,
|
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,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|
24
pubspec.lock
24
pubspec.lock
|
@ -917,14 +917,14 @@ packages:
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "5.1.0"
|
version: "5.1.0"
|
||||||
pinput:
|
pin_code_fields:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: pinput
|
name: pin_code_fields
|
||||||
sha256: e6aabd1571dde622f9b942f62ac2c80f84b0b50f95fa209a93e78f7d621e1f82
|
sha256: c8652519d14688f3fe2a8288d86910a46aa0b9046d728f292d3bf6067c31b4c7
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.2.23"
|
version: "7.4.0"
|
||||||
platform:
|
platform:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@ -1162,14 +1162,6 @@ packages:
|
||||||
description: flutter
|
description: flutter
|
||||||
source: sdk
|
source: sdk
|
||||||
version: "0.0.99"
|
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:
|
smooth_page_indicator:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
@ -1339,14 +1331,6 @@ packages:
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.3.1"
|
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:
|
url_launcher:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
|
|
@ -83,7 +83,7 @@ dependencies:
|
||||||
pdf:
|
pdf:
|
||||||
percent_indicator:
|
percent_indicator:
|
||||||
permission_handler:
|
permission_handler:
|
||||||
pinput:
|
pin_code_fields:
|
||||||
printing:
|
printing:
|
||||||
proj4dart:
|
proj4dart:
|
||||||
provider:
|
provider:
|
||||||
|
|
Loading…
Reference in a new issue