Skip to content

Commit 027dcc4

Browse files
ryleedavisryleedavisjulian-CStack
committed
Custom pin length (#555)
* WIP: pinCount stuff * pin decoration + and pinCount is 0 * pin length tweaks * fixes error when backspacing pin + add icon to flushbar * removed Constants.pinLength + changes to "change pin" setting * testing pin output * WIP: tests pass + commented out isRandom pin 1234 * removed pin output --------- Co-authored-by: ryleedavis <rylee@cypherstack.com> Co-authored-by: julian <julian@cypherstack.com>
1 parent c73c3af commit 027dcc4

File tree

7 files changed

+229
-195
lines changed

7 files changed

+229
-195
lines changed

lib/pages/pinpad_views/create_pin_view.dart

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'dart:async';
12
import 'dart:io';
23

34
import 'package:flutter/material.dart';
@@ -9,7 +10,6 @@ import 'package:stackwallet/providers/global/secure_store_provider.dart';
910
import 'package:stackwallet/themes/stack_colors.dart';
1011
import 'package:stackwallet/utilities/assets.dart';
1112
import 'package:stackwallet/utilities/biometrics.dart';
12-
import 'package:stackwallet/utilities/constants.dart';
1313
import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart';
1414
import 'package:stackwallet/utilities/text_styles.dart';
1515
import 'package:stackwallet/widgets/background.dart';
@@ -35,10 +35,11 @@ class CreatePinView extends ConsumerStatefulWidget {
3535
class _CreatePinViewState extends ConsumerState<CreatePinView> {
3636
BoxDecoration get _pinPutDecoration {
3737
return BoxDecoration(
38-
color: Theme.of(context).extension<StackColors>()!.textSubtitle3,
38+
color: Theme.of(context).extension<StackColors>()!.infoItemIcons,
3939
border: Border.all(
40-
width: 1,
41-
color: Theme.of(context).extension<StackColors>()!.textSubtitle3),
40+
width: 1,
41+
color: Theme.of(context).extension<StackColors>()!.infoItemIcons,
42+
),
4243
borderRadius: BorderRadius.circular(6),
4344
);
4445
}
@@ -57,10 +58,13 @@ class _CreatePinViewState extends ConsumerState<CreatePinView> {
5758
late SecureStorageInterface _secureStore;
5859
late Biometrics biometrics;
5960

61+
int pinCount = 1;
62+
6063
@override
6164
initState() {
6265
_secureStore = ref.read(secureStoreProvider);
6366
biometrics = widget.biometrics;
67+
6468
super.initState();
6569
}
6670

@@ -71,11 +75,13 @@ class _CreatePinViewState extends ConsumerState<CreatePinView> {
7175
_pinPutController2.dispose();
7276
_pinPutFocusNode1.dispose();
7377
_pinPutFocusNode2.dispose();
78+
7479
super.dispose();
7580
}
7681

7782
@override
7883
Widget build(BuildContext context) {
84+
// int pinCount = 1;
7985
return Background(
8086
child: Scaffold(
8187
backgroundColor: Theme.of(context).extension<StackColors>()!.background,
@@ -116,7 +122,7 @@ class _CreatePinViewState extends ConsumerState<CreatePinView> {
116122
height: 36,
117123
),
118124
CustomPinPut(
119-
fieldsCount: Constants.pinLength,
125+
fieldsCount: pinCount,
120126
eachFieldHeight: 12,
121127
eachFieldWidth: 12,
122128
textStyle: STextStyles.label(context).copyWith(
@@ -140,21 +146,23 @@ class _CreatePinViewState extends ConsumerState<CreatePinView> {
140146
),
141147
isRandom:
142148
ref.read(prefsChangeNotifierProvider).randomizePIN,
143-
submittedFieldDecoration: _pinPutDecoration.copyWith(
144-
color: Theme.of(context)
145-
.extension<StackColors>()!
146-
.infoItemIcons,
147-
border: Border.all(
148-
width: 1,
149-
color: Theme.of(context)
150-
.extension<StackColors>()!
151-
.infoItemIcons,
152-
),
153-
),
149+
submittedFieldDecoration: _pinPutDecoration,
154150
selectedFieldDecoration: _pinPutDecoration,
155151
followingFieldDecoration: _pinPutDecoration,
152+
onPinLengthChanged: (newLength) {
153+
setState(() {
154+
pinCount = newLength;
155+
});
156+
},
156157
onSubmit: (String pin) {
157-
if (pin.length == Constants.pinLength) {
158+
if (pin.length < 4) {
159+
showFloatingFlushBar(
160+
type: FlushBarType.warning,
161+
message: "PIN not long enough!",
162+
iconAsset: Assets.svg.alertCircle,
163+
context: context,
164+
);
165+
} else {
158166
_pageController.nextPage(
159167
duration: const Duration(milliseconds: 300),
160168
curve: Curves.linear,
@@ -184,7 +192,7 @@ class _CreatePinViewState extends ConsumerState<CreatePinView> {
184192
height: 36,
185193
),
186194
CustomPinPut(
187-
fieldsCount: Constants.pinLength,
195+
fieldsCount: pinCount,
188196
eachFieldHeight: 12,
189197
eachFieldWidth: 12,
190198
textStyle: STextStyles.infoSmall(context).copyWith(

lib/pages/pinpad_views/lock_screen_view.dart

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import 'package:stackwallet/themes/stack_colors.dart';
1313
// import 'package:stackwallet/providers/global/should_show_lockscreen_on_resume_state_provider.dart';
1414
import 'package:stackwallet/utilities/assets.dart';
1515
import 'package:stackwallet/utilities/biometrics.dart';
16-
import 'package:stackwallet/utilities/constants.dart';
1716
import 'package:stackwallet/utilities/enums/coin_enum.dart';
1817
import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart';
1918
import 'package:stackwallet/utilities/show_loading.dart';
@@ -189,10 +188,11 @@ class _LockscreenViewState extends ConsumerState<LockscreenView> {
189188

190189
BoxDecoration get _pinPutDecoration {
191190
return BoxDecoration(
192-
color: Theme.of(context).extension<StackColors>()!.textSubtitle2,
191+
color: Theme.of(context).extension<StackColors>()!.infoItemIcons,
193192
border: Border.all(
194-
width: 1,
195-
color: Theme.of(context).extension<StackColors>()!.textSubtitle2),
193+
width: 1,
194+
color: Theme.of(context).extension<StackColors>()!.infoItemIcons,
195+
),
196196
borderRadius: BorderRadius.circular(6),
197197
);
198198
}
@@ -202,6 +202,7 @@ class _LockscreenViewState extends ConsumerState<LockscreenView> {
202202

203203
late SecureStorageInterface _secureStore;
204204
late Biometrics biometrics;
205+
int pinCount = 1;
205206

206207
Widget get _body => Background(
207208
child: SafeArea(
@@ -274,13 +275,7 @@ class _LockscreenViewState extends ConsumerState<LockscreenView> {
274275
height: 52,
275276
),
276277
CustomPinPut(
277-
// customKey: CustomKey(
278-
// onPressed: _checkUseBiometrics,
279-
// iconAssetName: Platform.isIOS
280-
// ? Assets.svg.faceId
281-
// : Assets.svg.fingerprint,
282-
// ),
283-
fieldsCount: Constants.pinLength,
278+
fieldsCount: pinCount,
284279
eachFieldHeight: 12,
285280
eachFieldWidth: 12,
286281
textStyle: STextStyles.label(context).copyWith(
@@ -302,19 +297,7 @@ class _LockscreenViewState extends ConsumerState<LockscreenView> {
302297
.background,
303298
counterText: "",
304299
),
305-
submittedFieldDecoration: _pinPutDecoration.copyWith(
306-
color: Theme.of(context)
307-
.extension<StackColors>()!
308-
.infoItemIcons,
309-
border: Border.all(
310-
width: 1,
311-
color: Theme.of(context)
312-
.extension<StackColors>()!
313-
.infoItemIcons,
314-
),
315-
),
316-
selectedFieldDecoration: _pinPutDecoration,
317-
followingFieldDecoration: _pinPutDecoration,
300+
submittedFieldDecoration: _pinPutDecoration,
318301
isRandom: ref
319302
.read(prefsChangeNotifierProvider)
320303
.randomizePIN,

lib/pages/settings_views/global_settings_view/security_views/change_pin_view/change_pin_view.dart

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import 'package:stackwallet/providers/global/prefs_provider.dart';
66
import 'package:stackwallet/providers/global/secure_store_provider.dart';
77
import 'package:stackwallet/themes/stack_colors.dart';
88
import 'package:stackwallet/utilities/assets.dart';
9-
import 'package:stackwallet/utilities/constants.dart';
109
import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart';
1110
import 'package:stackwallet/utilities/text_styles.dart';
1211
import 'package:stackwallet/widgets/background.dart';
@@ -27,10 +26,11 @@ class ChangePinView extends ConsumerStatefulWidget {
2726
class _ChangePinViewState extends ConsumerState<ChangePinView> {
2827
BoxDecoration get _pinPutDecoration {
2928
return BoxDecoration(
30-
color: Theme.of(context).extension<StackColors>()!.textSubtitle2,
29+
color: Theme.of(context).extension<StackColors>()!.infoItemIcons,
3130
border: Border.all(
32-
width: 1,
33-
color: Theme.of(context).extension<StackColors>()!.textSubtitle2),
31+
width: 1,
32+
color: Theme.of(context).extension<StackColors>()!.infoItemIcons,
33+
),
3434
borderRadius: BorderRadius.circular(6),
3535
);
3636
}
@@ -48,6 +48,8 @@ class _ChangePinViewState extends ConsumerState<ChangePinView> {
4848

4949
late final SecureStorageInterface _secureStore;
5050

51+
int pinCount = 1;
52+
5153
@override
5254
void initState() {
5355
_secureStore = ref.read(secureStoreProvider);
@@ -101,7 +103,7 @@ class _ChangePinViewState extends ConsumerState<ChangePinView> {
101103
height: 52,
102104
),
103105
CustomPinPut(
104-
fieldsCount: Constants.pinLength,
106+
fieldsCount: pinCount,
105107
eachFieldHeight: 12,
106108
eachFieldWidth: 12,
107109
textStyle: STextStyles.label(context).copyWith(
@@ -125,21 +127,18 @@ class _ChangePinViewState extends ConsumerState<ChangePinView> {
125127
),
126128
isRandom:
127129
ref.read(prefsChangeNotifierProvider).randomizePIN,
128-
submittedFieldDecoration: _pinPutDecoration.copyWith(
129-
color: Theme.of(context)
130-
.extension<StackColors>()!
131-
.infoItemIcons,
132-
border: Border.all(
133-
width: 1,
134-
color: Theme.of(context)
135-
.extension<StackColors>()!
136-
.infoItemIcons,
137-
),
138-
),
130+
submittedFieldDecoration: _pinPutDecoration,
139131
selectedFieldDecoration: _pinPutDecoration,
140132
followingFieldDecoration: _pinPutDecoration,
141133
onSubmit: (String pin) {
142-
if (pin.length == Constants.pinLength) {
134+
if (pin.length < 4) {
135+
showFloatingFlushBar(
136+
type: FlushBarType.warning,
137+
message: "PIN not long enough!",
138+
iconAsset: Assets.svg.alertCircle,
139+
context: context,
140+
);
141+
} else {
143142
_pageController.nextPage(
144143
duration: const Duration(milliseconds: 300),
145144
curve: Curves.linear,
@@ -165,7 +164,7 @@ class _ChangePinViewState extends ConsumerState<ChangePinView> {
165164
height: 52,
166165
),
167166
CustomPinPut(
168-
fieldsCount: Constants.pinLength,
167+
fieldsCount: pinCount,
169168
eachFieldHeight: 12,
170169
eachFieldWidth: 12,
171170
textStyle: STextStyles.infoSmall(context).copyWith(
@@ -192,17 +191,7 @@ class _ChangePinViewState extends ConsumerState<ChangePinView> {
192191
),
193192
isRandom:
194193
ref.read(prefsChangeNotifierProvider).randomizePIN,
195-
submittedFieldDecoration: _pinPutDecoration.copyWith(
196-
color: Theme.of(context)
197-
.extension<StackColors>()!
198-
.infoItemIcons,
199-
border: Border.all(
200-
width: 1,
201-
color: Theme.of(context)
202-
.extension<StackColors>()!
203-
.infoItemIcons,
204-
),
205-
),
194+
submittedFieldDecoration: _pinPutDecoration,
206195
selectedFieldDecoration: _pinPutDecoration,
207196
followingFieldDecoration: _pinPutDecoration,
208197
onSubmit: (String pin) async {

lib/utilities/constants.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ abstract class Constants {
3939
static const int notificationsMax = 0xFFFFFFFF;
4040
static const Duration networkAliveTimerDuration = Duration(seconds: 10);
4141

42-
static const int pinLength = 4;
43-
4442
// Enable Logger.print statements
4543
static const bool disableLogger = false;
4644

lib/widgets/custom_pin_put/custom_pin_put.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ class CustomPinPut extends StatefulWidget {
5353
this.mainAxisSize = MainAxisSize.max,
5454
this.autofillHints,
5555
this.customKey,
56-
}) : assert(fieldsCount > 0),
57-
super(key: key);
56+
this.onPinLengthChanged,
57+
}) : super(key: key);
58+
59+
final void Function(int)? onPinLengthChanged;
5860

5961
final double? width;
6062
final double? height;

0 commit comments

Comments
 (0)